Question

I am writing this space tower defense game based on defending the planet . The guns have a 260 degree firing range, they also are orbiting the planet. the creeps can come in every direction (360 degrees around the planet). I want the gun to smartly target the creep, aiming to where the bullet will hit the creep and not where the creep is.

I was wondering how to calculate where the bullet will intercept the alien.

Thanks in advance

Note:This is not homework nor is am i asking you to write code. I just don't understand the math to solve this problem.

These are the things i know: Creep's speed, creeps position, creeps destination, Bullets speed, bullets original position. I do not know any angles. I would show you a picture, but apparently i don't have enough reputation points

Currently i have it implemented that the bullet gets updated with the creeps position so the bullet bends with the creep. It's highly inefficient and not how i want it at all.

Was it helpful?

Solution

Basically, you get a system of two equations: enter image description here where |XY| is distance between two points. You must be able to solve that system and figure out the coordinates Xp,Yp of the intersection point. For more info:

http://en.wikipedia.org/wiki/Linear_equation

http://en.wikipedia.org/wiki/Euclidean_distance

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top