Hi,
I have an object ejected like a ball from a cannon and I want to know where it will be on the ground (before their collision with the ground).
In other words, I want to get the collision destination position of the ball in the ground.
Something like using a ray cast from the ball to the ground.
Thanks in advance
How to determine/predict collision
Re: How to determine/predict collision
If the projectile is sufficiently fast then a ray cast will be a sufficient approximation. If it's not, then you can either use kinematics or use Bullet to simulate the projectile's motion. To my knowledge, there is no equivalent of a ray cast for parabolic, (or indeed any non-linear motion), so you would have to manually step through the simulation until your projectile hit the ground. That could be easily enough determined by looking at its y coordinates over time. Is there any particular reason you can't use kinematics?
- Erwin Coumans
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
- Contact:
Re: How to determine/predict collision
If you know the begin and end position, you can use the btCollisionWorld::convexSweepTest to find the time of impact.
convexSweepTest assumes constant linear and angular motion.
Thanks,
Erwin
convexSweepTest assumes constant linear and angular motion.
Thanks,
Erwin
Re: How to determine/predict collision
Sorry, ignore everything I just said.
Re: How to determine/predict collision
Erwin Coumans wrote:If you know the begin and end position, you can use the btCollisionWorld::convexSweepTest to find the time of impact.
convexSweepTest assumes constant linear and angular motion.
Thanks,
Erwin
The problem is that I don't know the end position.
Also, the most important part is that I want to know the end position to receive the ball with another object
To get a better idea, it will be like a ping pong, so I need a way to get the end position to move the CPU paddle.
Thanks
Re: How to determine/predict collision
How about as soon as you start your trajectory have a loop go through the motion with simulated timesteps until it collides without doing any rendering? Then knowing the end point reset the physics simulation, and using the same timesteps go through the whole thing again, this time rendering and manipulating your AI and then once it collides (if your AI is successful) start the process over. You will have to get the determinism stuff right, but it seems doable.
Another approach would be to have your AI actually use some simple AI rather than prior knowledge and just interpret the current trajectory and try to anticipate where the object will end up and start moving there, and update based on the progress of the object.
Another approach would be to have your AI actually use some simple AI rather than prior knowledge and just interpret the current trajectory and try to anticipate where the object will end up and start moving there, and update based on the progress of the object.
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
- Contact:
Re: How to determine/predict collision
You could shoot lots of rays, i.e. the more rays, the closer it would be too a true curve. I have considered this for certain kinds of vehicle suspension such as the rear or a motorbike, where the suspension does not go up/down but around an arc. Obviously the performance will not be great but you you can control the number of rays and you may find there is an acceptable sweet spot.
Re: How to determine/predict collision
I hate to be too old-fashioned here, but you could always do this:
Where t_1, x_1, z_1 are the time, x-position, and z-position respectively of the ball's impact with the table. Then after the collision you can calculate the difference in the difference in each component of the velocity induced by spin and imperfections in the collision and use those new velocities to find the point where it intersects the plane at the back of the table. In fact, you might not even want to have it calculate for spin if you want to give the player a "surprise factor" when he uses spin.
Code: Select all
0 = -(1/2)g(t_1)^2 + (v_y)(t_1) + (y_0)
t_1 = (-(v_y) +/- sqrt((v_y)^2 + 2g(y_0)))/(-g)
x_1 = (v_x)(t_1)
z_1 = (v_z)(t_1)