- Home /
Prevent ball from going straight on x and y axis
Hi
I am making a small pong style game for Android and are almost done. I have on problem though.
Sometimes the ball will hit a corner and get sent almost straight on the x or y axis. I can see that it's still moving on that axis, but only so slightly. It might take a couple of minutes to get clear or for the ball to hit something that changes it's direction.
How can I prevent the ball from going straight on x and y axis?
Answer by Rasp1977 · Jul 13, 2012 at 06:54 PM
I am using physics. Rigidbody with no drag or gravity.
It should be possible to find the direction the ball is going in and check if x is less than a specific number. If it is, then add a bit of force in that direction only.
Just don't know how to detect that the ball is not moving enough on one axis.
rigidbody.velocity.x should give you the current speed in x direction.
It's working.
Just check if rigidbody.velocity.x and add force to it if it gets below a certain amount.
Thx
Answer by Piflik · Jul 13, 2012 at 05:48 PM
Are you using physics simulation, or are you calculating the ball's reaction to the collision yourself? Don't know if you can limit the angle with physics (probably not), when you calculate it yourself, it should be possible, but how exactly I can't say without seeing you code.
Personally I would calculate the outgoing angle of the ball based on the inbound angle and the location on the racket, within certain limits (+-60° probably).
Your answer
Follow this Question
Related Questions
Simple Collision Deflection (Pong) 1 Answer
pong rolling ball 1 Answer
How to accelerate the ball in a pong clone 1 Answer
change ball direction when hitting paddle 1 Answer
Scoring not working 2 Answers