- Home /
Bounce collision vs. constrained rigidbody
Okay, sort of nooby.
For my first real game I'm trying a Breakout/Arkanoid style thing, and I'm trying to work out the physics of this.
My paddle has a constrained rigidbody, but when the ball collides with that, it absorbs the entire collision. The ball doesn't bounce back at all.
Everything has a material bounciness of 1, and if I don't have a rigidbody on it, it's fine. Except I was using the rigidbody on the paddle to keep it in the bounds of the playfield, and without it, I'm moving the paddle through translate() rather than through its velocity, and I think moving it by velocity will be better for the case when the ball clips the corner of the moving paddle.
So is there an alternate way to constrain the position of the paddle or what should I try to ensure the bounciness of the ball?
Answer by justinl · Sep 18, 2012 at 03:02 AM
After discussion, the answer is:
Set the paddle object as a RigidBody with Kinematic property checked.
Use rigidbody.MovePosition() to control movement of the paddle.
Answer by justinl · Sep 16, 2012 at 03:33 AM
You could constrain the paddle position simply by defining your "left and right" bounds. For instance this would keep the paddle between 0 and 100 along the x-axis:
if(myPaddle.transform.position.x > 100)
myPaddle.transform.position.x = 100; //you can't set this value like this explicitly but this is just an example code
else if (myPaddle.transform.position.x < 0)
myPaddle.transform.position.x = 0;
EDIT
After discussion, the answer to the original question is:
Set the paddle object as a RigidBody with Kinematic property checked.
Use rigidbody.MovePosition() to control movement of the paddle.
ps - I think you'd have to set the new position as: myPaddle.transform.position = new Vector3(100, myPaddle.transform.position.y, myPaddle.transform.position.z);
Okay, but if the paddle has no velocity can I get the ball to rebound the same as if the paddle was moving?
Because there were things I liked about having a rigidbody collision, like how the ball responds to the current velocity of the paddle. But if I'm just moving with Translate, then it has no velocity.
You can still keep the paddle as a rigidbody and constrain it's axis.
But that takes me back to my first problem that a constrained rigidbody loses energy when it bounces a ball.
I made a video that shows the differences: https://vimeo.com/49625612
I like how the ball bounces off the static collider except for it doesn't change the velocity of the bounce or add spin when it's moving. I like how the ball bounces off the unconstrained rigidbody, except for how the paddle gets knocked out of position. And with the constrained rigidbody, the ball loses energy when it bounces, like it's not really conserving momentum.
I can approximate what I want by making a very heavy constrained paddle, but it will still lose a small amount of momentum, and if there's a nice way to hold the position of something while still conserving momentum, it would be nice to know about.
Your video is private by the way (I can't view it). Try putting a checkmark in the "$$anonymous$$inematic" property on the paddle rigid body. I think that'll solve your "getting knocked out of place" issue. As for maintaining momentum, you could set a $$anonymous$$imum velocity on the ball. So in your ball update script, you can make sure that the velocity parameter does not go below a certain value. This way, the ball can "speed up" if you hit it hard, but yet it will never slow down so much that it stops or becomes too slow.
Your answer
Follow this Question
Related Questions
How do I use rigidbody's collision detection modes? 2 Answers
Rigidbodies won't collide if mass difference is too high 0 Answers
Guidelines for using rigidbody, collider, CharacterControllerScript, etc? 3 Answers
How to get collisions on Character controller? 1 Answer
OnCollisionEnter isnt called when player lands on object 1 Answer