- Home /
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?
Answer by fafase · Nov 25, 2013 at 11:41 AM
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.
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
Your answer
Follow this Question
Related Questions
Simulating the graphics of a rolling 3D ball in a 2D game 2 Answers
Player-controlled rigidbody ball sometimes slowing down for no reason 0 Answers
How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers
Ball jump on collision problem 1 Answer
UnityEditor > Assign a Physics Material from asset folder to colliders component of objects 1 Answer