Hi All....
I am doing ping pong game where I have to move ball and detect collision with outside boundary and also with moving paddle. I want to implement it using vector and not by trigonometry.
I am very weak in math,so kindly guide me.
Hi All....
I am doing ping pong game where I have to move ball and detect collision with outside boundary and also with moving paddle. I want to implement it using vector and not by trigonometry.
I am very weak in math,so kindly guide me.
You'll probably need to be more specific about what you need. The key thing to know is that when bouncing the ball, the angle of incidence equals the angle of reflection. However, in pong like games, they usually alter the angle based on the part of the paddle that it hit (as if the paddle were an arc).
For using a vector, it has a start point and a slope. If the start point is the left side of the screen (x == 0), then you are in luck, because the normal slope intercept formula works well
Y = mX + B
Where M is slope and B is the where it crosses the Y-Axis (the value of Y when X is 0). Then increment X some amount and calculate Y. On the return hit, you can do this backwards. m is 0 when the vector is perfectly horizontal. When it hits the paddle, to preserve angle of incidence == angle of reflection -- you just need to use -m (adjusted for the position on the paddle).
Anyway -- if you have any questions, comment on this answer or update your question and I will try to provide more info.
There's a great tutorial on GameDev.net on Collision Detection. It's an OpenGL tutorial, and I don't know if you're using OpenGL, but the math is the same, so I think it'll be useful.