Intersecting Vectors(python programming)

  • Context: Python 
  • Thread starter Thread starter woods9910
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary
SUMMARY

This discussion focuses on calculating the aiming angle for a ship in the game Xpilot, given specific variables such as self coordinates, velocity, heading direction, enemy coordinates, and bullet speed. The user seeks to determine the angle required to hit a moving enemy ship, using the example of their ship at (0, 0) with a velocity of 10 and heading of 60 degrees, while the enemy is at (100, 100) with a velocity of 5 and heading of 120 degrees. The challenge lies in calculating the correct angle (theta) to ensure the bullet, traveling at a speed of 10, intersects with the enemy's trajectory. The discussion emphasizes the need for vector calculations to solve this problem.

PREREQUISITES
  • Understanding of vector mathematics in 2D space
  • Familiarity with Python programming for implementing calculations
  • Knowledge of basic physics principles related to motion
  • Experience with game development concepts, particularly in AI behavior
NEXT STEPS
  • Research vector projection techniques in Python
  • Learn about solving systems of equations to find intersection points
  • Explore the use of trigonometric functions for angle calculations
  • Investigate game physics libraries in Python, such as Pygame or Pymunk
USEFUL FOR

This discussion is beneficial for game developers, particularly those working on AI mechanics in real-time strategy or physics-based games, as well as programmers looking to enhance their understanding of vector mathematics and motion prediction in gaming contexts.

woods9910
Messages
1
Reaction score
0
I am doing a project for a a programming class where we create AI bots for the game Xpilot. Xpilot is a space physics game where you control a ship that attempt to shoot other ships. I am attempting to create an aiming function for the ship, but cannot figure out the physics of it.

The given variables are:
-self coordinates, velocity, heading direction, and bullet speed
-enemy coordinates, velocity, and tracking direction

My question is:
Given these variables, how do I calculate the angle that I must aim at in order to hit the enemy moving at a constant velocity. So, for example, my ship is at (0, 0) moving at 60 degrees and v= 10, and the enemy ship is at (100, 100) moving at 120 degrees and v = 5. If the bullet speed is 10, what angle must I shoot at to hit the enemy?

Im not exactly sure what I'm looking for as the final product here. I know how to calculate the bullet's vector and the enemy's vector, but I'm not really sure how to find theta that makes this an accurate start. If someone could start me off in the right direction or give me a general idea of how to go about this it would be much appreciated.
 
Technology news on Phys.org
If you are not sure which way to go a good drawing my get you headed in the right direction.
 

Attachments

  • spaceship195.jpg
    spaceship195.jpg
    22.5 KB · Views: 511

Similar threads

Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K