I am make 2D platforming game in Unity and I have a problem: If my player goes over an edge the player falls along an arc trajectory. I want to make the player fall over the edge like a stone? Unable to alter the value of gravity.
Asked
Active
Viewed 128 times
-2

silentsod
- 8,165
- 42
- 40
-
It will be better if u explain what a falling like a stone means ? – utkdub Jan 29 '17 at 09:53
-
Do u wanna say not rotating just being still while falling ? – utkdub Jan 29 '17 at 09:53
-
When player walking over edge, I want : player fall like stone (absolute vertically) – Jan 31 '17 at 21:25
1 Answers
1
Assuming that you are using 2D Physics with Rigidbody2D and Collider2D, you could, in your player script, set the horizontal velocity to 0 if the player is not grounded. To check if he is grounded, take a look at Physics2D.CircleCast()
.
So you could add something like this to your script:
Rigidbody2D rb2d = GetComponent<Rigidbody2D>();
if (isGrounded == false)
rb2d.velocity = new Vector2(0, rb2d.velocity.x);

Ian H.
- 3,840
- 4
- 30
- 60
-
2What do you mean "does not work"? Be sure that you only add force to your player from the input, if `isGrounded = true`. – Ian H. Jan 29 '17 at 21:34
-
@Adam This isn't a code writing site. I provided you with some useful information that you can use. One last tip i can give you is to take a look at `Physics2D.LineCast` and check down if a floor exists. – Ian H. Jan 31 '17 at 21:29