Calculate Intersection Point for Shooting Drifting Ship in Video Game

  • Thread starter Thread starter Rythious
  • Start date Start date
  • Tags Tags
    Homework
Rythious
Messages
1
Reaction score
0
I didn't know where else to place this as I have yet to do the work, but I want to, I just don't know what formulas I need. I've been out of school for a while and can't remember or can't figure out all the formulas I need so I'll tell you my problem and if someone could just post the relevant equations I'd like to solve the problem myself.

I used to play this video game which was a top down space shooter, you controlled a ship which would drift if you stopped using the boosters. There was no acceleration (positive or negative) while the boosters weren't used, you'd just drift in a straight line. I wanted to try and program a turret to shoot at these drifting ships. This is all done in virtual space and there is no acceleration at all, even the bullets shot reached their target velocity instantly and remained there. So, here's what I know. Given two times to collect coordinates of the ship, I can formulate the line it's traveling. I already know that part. But knowing the time in between those two captured sets of coordinates I know I should be able to derive the ships velocity. While knowing the coordinates of the turret itself and the speed at which it's own bullets travel, I'm trying to find what line it should fire on to intersect with the ship at the right time. I'm probably forgetting something, but I'm off to work, just wanted to throw this up quick. I'll post in about 16 hours if there's any thing I left out. If you think all the info is there I'd really appreciate someone just posting the formula to calculate which intersection point I could hit given my bullet's traveling speed and the ships traveling speed.
 
Ok. Here's one approach. Let the position of the ship be S, the position of the turret be T, position where bullet collides with the ship be H, velocity of the ship=vs and velocity of bullets=vb. It's easiest to talk about this if we choose a special coordinate system, so let S=(0,0), T=(d,0), H=(x,y), now we can write the path of the ship as y=m*x for some slope m. One condition for a successful intercept is that the flight time of the ship is equal to the flight time of the bullet. So set |HS|/vs=|HT|/vb (time=distance/velocity). Squaring both sides gives a quadratic in x and y. Eliminate y (e.g.) from the quadratic by setting y=mx. Solve the resulting quadratic. Bingo. Be sure and check for spurious roots (e.g. the intersection point may be on the reverse path of the ship, not the forward part - there may also be no roots or multiple good roots).
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 98 ·
4
Replies
98
Views
11K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
90
Views
14K
  • Poll Poll
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 52 ·
2
Replies
52
Views
9K
  • · Replies 11 ·
Replies
11
Views
2K