Aiming spaceship turrets

Blitz3D Forums/Blitz3D Programming/Aiming spaceship turrets

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I think you need to solve two equations at the same time...

You have one equation that reprents the line along which the space ship is currently traveling.

You have another equation that represents the turret's line of sight.

The turret's line of sight equation is full of unknowns since you don't know where this line should point.

There are also two additional values that come into play. The speed of the ship, and the speed of the bullet.

Now when I sketch this out on paper, it becomes apparent that I could hit the ship at any number of locations along it's line of travel. We have to choose a location to hit. I guess the ideal location to hit would be the location where the ship has to travel the shortest distance.

Hm...

What you want is you want to:

A) Take ship-line and calculate turret-line such that intersection point of turret line is equal to how far the bullet would travel if fired at this moment.

Ie, the more perpendicular the two lines are, the less time it will take for the bullet to reach the target point.

Boy this is tough to explain... Especially when I don't know what I'm doing myself. :-)

Okay we know the player's ship line is fixed.

Now, for each point along that line, it is associated with a certain time in the future.

That time is the time at which the player's ship will arrive there if it remains on it's current course.

Aha...

So, our goal is to find a point where the turret line of sight intersects the ship line.... And this point has to have the same time on both lines.

We know these:
Ship_X#
Ship_Y#
Ship_Z#

ShipVector_Nx#
ShipVector_Ny#
ShipVector_Nz#

Turret_X#
Turret_Y#
Turret_Z#

TurretBullet_Speed#
Ship_Speed#

We do not know these:
TurretVector_Nx#
TurretVector_Ny#
TurretVector_Nz#

ShipVector_IntersectionDistance#
TurretVector_IntersectionDistance#



IntersectionDistance# is the world distance from the start of the vector to the point of intersection.

Speed# is a value which tells us what distance along the vector is equal to what amount of time.

For example, if Speed# is 2.0, then traveling one unit along the vector takes 2 seconds.


Now, we need to find a point along the ship's line where:

ShipVector_IntersectionDistance#*Ship_Speed# = TurretVector_IntersectionDistance#*TurretBullet_Speed#

It turns out there are lots of such points.

Hm...

You know, there are much easier ways of doing this. :-) Like for example, simply dtermining when the ship is within a certain distance of the turret, and firing in it's general direction. :-)