Join #ludumdare on irc.afternet.org
Mini LD #3 :: September 5th-7th Weekend :: Theme :: Tool

Sign In | Write your Journal
Home | Planet Ludum | Rules Wiki | Mailing List

Ludum Dare 12 Final Results NOW AVAILABLE

Click HERE for the Ludum Dare 12 entries image grid
(to be included in the image grid, you must upload an image to the blog)

Re: Distractions Deluxe

Posted by LunarCrisis

My solution:

So the problem is to figure out the direction a player (moving in 3-d) has to shoot to hit an enemy (also moving in 3-d) given their positions, velocities, and the speed of the bullet.

The approach I used was to solve the equation

time it takes the enemy to reach a position = time it takes the bullet to reach the position

for the time.

First, redefine the vectors so that they are all relative to the player. This
leaves you with only bullet speed, enemy velocity, and enemy position. The
points in question are the points along the enemy’s trajectory, so express the
above equation in terms of t:

b1.png

This can be solved with the quadratic equation:

b21.png

Note that there may be zero, one, or two solutions. Negative solutions reflect hits in the past. If there are no positive solutions it is not possible for the player to hit the enemy.

Once you have t, it is simple to calculate the position.

Edit: forgot the exponent on the bottom of the final answer.

Tags: , , , ,

One Response to “Re: Distractions Deluxe”

  1. DrPetter Says:

    Looks great… in all its gritty mathyness. I might inspect it in the morning, but that hour of equation-wielding on irc bled me dry for the day so I will just take your word for it until then ;)

Leave a Reply


All posts, images, and comments are owned by their creators.