Python Intersecting Vectors(python programming)

  • Thread starter Thread starter woods9910
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary
To calculate the angle needed to hit a moving enemy in Xpilot, you need to account for both the ship's and enemy's velocities, as well as the bullet speed. Start by determining the enemy's future position based on its current velocity and heading. Use vector mathematics to find the intersection point where the bullet will meet the enemy, factoring in the bullet's speed. The angle to aim can be derived from the vector pointing towards this intersection point relative to your ship's current heading. A visual representation may help clarify the relationships between these vectors and assist in determining the correct angle.
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: 503
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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