Prediction

Discuss new features and future development.

Prediction

Postby LegoCylon » Wed Jul 10, 2013 2:30 am

I needed to predict when a body and a projectile will collide in order to figure out where to fire the projectile. If you assume circular shapes (since you can then ignore rotation) and constant velocity, time can be solved for with a quadratic equation. If you want to account for constant acceleration or include gravity, damping, etc, then you'll need to solve a quartic equation which is much more challenging.

I found this to be much more appealing then the typical suggestion I saw - cloning your space and quickly simulating all objects in advance. While the quadratic/quartic formula doesn't account for other bodies that might intercede between the predicting bodies, I am dealing with that by using "sweeping" segment queries to look for static geometry between the initial position and point of impact. This seems to work quite well for me even though it doesn't catch all cases.

Predicting time of impact for shapes beyond circles could probably be done by doing a "broad phase" using circle-circle prediction to detect time of "bounds" impact and separation and simulating body motion in between those times to check for an actual collision.

While I've solved this as far as my game needs, this seems like it could be a common need, so I wondered if it made sense to add these kinds of calculations to the API. I'd be happy to help adapt my solutions if you're interested.

P.S. I think solving for the time of intersection could also help with tunneling problems due to very fast moving bodies.
There's a really good article on solving non-linear trajectory collisions here:
http://twobitcoder.blogspot.com/2010/04 ... inear.html
LegoCylon
 
Posts: 29
Joined: Wed May 09, 2012 12:06 am

Return to Features/Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron