Calculate Intersection Point for Shooting Drifting Ship in Video Game

  • Thread starter Rythious
  • Start date
  • Tags
    Homework
In summary, the speaker is seeking help with finding the appropriate formulas to calculate the intersection point of a turret's bullet with a drifting ship in a virtual space video game. They have provided some information about the ship's movement and the turret's position and bullet speed, but are unsure of the exact formulas needed. They suggest a potential approach involving setting up a quadratic equation and solving for the intersection point.
  • #1
Rythious
1
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
  • #2
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).
 
  • #3


Hello,

Thank you for reaching out with your problem. I can definitely help you with this issue. First, let's break down the problem into smaller parts to make it easier to solve.

1. Finding the ship's velocity: Since you have the coordinates of the ship at two different times, you can use the formula for average velocity, which is velocity = (change in position)/(change in time). In this case, the change in position would be the difference between the two sets of coordinates, and the change in time would be the time between them. Once you have the average velocity, you can use it as the ship's velocity in your calculations.

2. Finding the intersection point: To find the intersection point, you will need to use the equation of motion, which is x = x0 + v0t + 1/2at^2. In this case, x0 is the initial position of the bullet (turret's coordinates), v0 is the initial velocity of the bullet (bullet's speed), t is the time it takes for the bullet to reach the intersection point, and a is the acceleration (which is 0 in this case since there is no acceleration).

To find the time, you can use the formula t = (x-x0)/v0, where x is the x-coordinate of the ship and x0 is the x-coordinate of the turret.

Once you have the time, you can plug it back into the equation of motion to find the y-coordinate of the intersection point.

3. Final steps: Now that you have the coordinates of the intersection point, you can use the distance formula to calculate the distance between the turret and the intersection point. If this distance is less than the range of the turret's weapon, then the turret can fire at the intersection point to hit the drifting ship.

I hope this helps you in solving your problem. Let me know if you need any further assistance or if you have any other questions. Good luck with your programming!
 

Related to Calculate Intersection Point for Shooting Drifting Ship in Video Game

1. What is the purpose of calculating the intersection point for shooting drifting ships in a video game?

The purpose of calculating the intersection point is to determine the exact location where the player's projectile will meet the moving target, allowing for more accurate and successful shots. This adds an element of skill and strategy to the game, as the player must take into account the speed and direction of the drifting ship to land a hit.

2. How is the intersection point calculated?

The intersection point is calculated using mathematical equations that take into account the position, velocity, and trajectory of both the player's projectile and the drifting ship. This information is constantly updated in real-time to ensure accuracy.

3. Can the intersection point calculation be affected by in-game factors?

Yes, there are several in-game factors that can affect the accuracy of the intersection point calculation. These include the player's aim and skill, environmental factors such as wind or obstacles, and the speed and movements of the drifting ship.

4. Is the intersection point calculation the same for all types of video games?

No, the intersection point calculation may vary depending on the type of video game. For example, a first-person shooter game may use different equations and factors compared to a strategy game or a racing game.

5. Are there any limitations to the intersection point calculation in video games?

While the intersection point calculation is constantly being improved and refined, there may still be some limitations. Factors such as lag or latency in online games can affect the accuracy of the calculation, and it may not take into account all possible variables in a complex game environment.

Similar threads

  • Sci-Fi Writing and World Building
Replies
18
Views
2K
  • Sci-Fi Writing and World Building
Replies
15
Views
1K
  • Special and General Relativity
3
Replies
98
Views
3K
  • Introductory Physics Homework Help
Replies
26
Views
3K
Writing: Input Wanted Captain's choices on colony ships
  • Sci-Fi Writing and World Building
Replies
4
Views
2K
  • Sci-Fi Writing and World Building
3
Replies
90
Views
6K
  • Sci-Fi Writing and World Building
2
Replies
52
Views
4K
  • Introductory Physics Homework Help
Replies
26
Views
2K
  • Sci-Fi Writing and World Building
3
Replies
96
Views
6K
Replies
9
Views
1K
Back
Top