Calculate Intersection Point for Shooting Drifting Ship in Video Game

  • Thread starter Thread starter Rythious
  • Start date Start date
  • Tags Tags
    Homework
Click For Summary
SUMMARY

This discussion focuses on calculating the intersection point for a turret to hit a drifting ship in a top-down space shooter video game. The key variables include the ship's position (S), turret's position (T), bullet's collision point (H), ship's velocity (vs), and bullet's velocity (vb). The approach involves establishing a coordinate system and using the relationship between flight times of the ship and bullet, leading to a quadratic equation that can be solved for the intersection point. Important considerations include checking for spurious roots to ensure the intersection point is valid.

PREREQUISITES
  • Understanding of basic physics concepts such as velocity and distance
  • Familiarity with coordinate systems and linear equations
  • Knowledge of quadratic equations and their solutions
  • Experience with programming concepts for game development
NEXT STEPS
  • Research "Projectile motion equations in 2D" for further insights on bullet trajectories
  • Learn about "Quadratic equation solving techniques" to handle the derived equations
  • Explore "Game physics engines" to understand how they simulate motion and collisions
  • Investigate "Coordinate transformations" for more complex movement scenarios in games
USEFUL FOR

Game developers, particularly those working on physics simulations, programmers designing shooting mechanics, and anyone interested in implementing accurate targeting systems in video games.

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.
 
Physics news on Phys.org
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 18 ·
Replies
18
Views
5K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 98 ·
4
Replies
98
Views
9K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
90
Views
13K
  • Poll Poll
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 52 ·
2
Replies
52
Views
8K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 96 ·
4
Replies
96
Views
12K