Make my ball ONLY bounche up

I made a small ball game with the new 2d functions. Ive made some platforms, and the player which is the ball. i added physic material to my ball, so it constantly bounches. But when it hits the edge of my platform colliders it bounches to the side. (Imagine if you bounched a ball in real life into the edge of a table) How do i make it stop during that?

1 Answer

1

Constrain the rigidbody to move only in the y direction so that bouncing in x direction is not considered.

I know how to do that in original rigidbody, but i can't find the constrants on 2d rigidbody.

oh ok. Well, indeed I do not see any constrain, bit I see velocity. So you could set the x velocity to 0 when hitting the sides of your game.

Do i need to script the velocity?

it is already in the rigidbody component. You could do that: void OnCollisionEnter(Collision col) { if(col.gameObject.tag == "Side"){ Vector3 vel = rigidbody.velocity; vel.x = 0; rigidbody.velocity = vel; } } it also depends on how you move your object, if you launch the ball with initial velocity and then you let the engine do then it should be fine.

Im scripting java, so i can't fix the bugs in your script. but it says: .Assets/EdgeFail.cs(1,6): error CS0116: A namespace can only contain types and namespace declarations