-2

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.enter image description here

silentsod
  • 8,165
  • 42
  • 40

1 Answers1

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
  • 2
    What 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