Planet of the Timmies
April 5th, 2011 at 12:04 am

So tonight I added in anti-aircraft guns into the game. Although they shoot, they don’t do any damage yet.

image

The actual model is a handful of cylinders and boxes; but for now I’m not too interested in how it looks. The interesting bit today was the bit that works out aim the gun so that the bullets travelling at speed b will collide with the plane travelling with velocity v at some time in the future t. My Maths is rather tragically rusty and it took me a considerable time to work out.

As it turns out you have end up having the bullet as a sphere of radius st on one side of the equation and the plane as a line parameterised by t on the other. If you rearrange the equation you can form it into a classic quadratic that you can then solve with the old x = (-b +/- sqrt(b^2 – 4ac)) / 2a formula. This normally gives you two possible times at which the bullet and the plane should collide, although one of them may be negative (in the past), in which case the only person you’ll hit is Dr. Who.

Once you have the time the bullet and the plane will collide you can work out where the plane will be at that time and aim there.

This currently only works for planes travelling in a straight line, but for now it’ll do.


No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.