- Home /
Trying to get a ball to bounce realistically in 2D.
So my game has the player control a paddle with the mouse and they have to keep a ball in the air. If you push the paddle up to the ball to hit it I expect the ball to bounce off from the force but it just moves with the paddle till you move it away. I've tried to mess around with values and it seems to help a little bit but not exactly. I hope this makes sense, I'm not sure if this would be a thing I have to program to do or if I can just mess with Unity to get those results. Thanks everyone!
Answer by springwater · Jul 10, 2017 at 06:40 AM
I think you should post your code, seems like ForceMode.Force needs to be applied to the balls rigid body at the collision position on collision. Pretty much as Arpian says below whereas your ball must be a rigid body, or you need to access it rigidbody component.. but still ForceMode.Force seems like the right choice as well.
I don't actually have any code for making the ball bounce, it's all just the physics material 2D that I'm using, I'll try adding code for it though, I'll try what @Arpian was saying because that seems like it'll work!
Answer by Vollmondum · Jul 10, 2017 at 06:41 AM
yourBall.AddForce(transform.Vector3(direction you want it to bounce) * speed * Time.deltaTime);
Direction is usually perpendicular from the collision spot. Also check your ball's mass in rigidbody. If it bounces too slow, shrink down everything in your scene to 0.1. And well, play with that object size value.
Your answer
Follow this Question
Related Questions
Help with 2D physics script 1 Answer
How to rotate a GameObject with another GameObject while simulating gravity? 2 Answers
Limit player speed (2D) 3 Answers
Get information on ignored collision 1 Answer