- #1
hospadar
- 2
- 0
I want to make a simple little video game with spaceships in it. The game only takes place in 2 dimensions, although I suspect any math would be applicable to more dimensions.
The spaceships:
- Have a set turning speed (radians/sec, different ships may be able to turn faster or slower)
- Have a maximum speed (not realistic for space, but better for video games)
- Have thrusters which only provide thrust in a limited number of fixed directions. Most likely only forwards or only forwards and backwards.
- The spaceships will have inertia, and there will be no friction acting on them
- There will be no (predictable) forces acting on the spaceship other than the thrusters, no gravity, etc.
- The mass/inertia of the ship doesn't change ever
The User will specify where they want their spaceship to end up, and the heading and speed they want to have when their ship arrives at the destination. So I need to take an initial position and velocity, a final position and velocity, and generate a set of turns and thruster firings that will deliver the ship to the final position at the correct velocity.
So what I need to figure out is how to actually compute the best trajectory, when to turn, when to thrust, etc. It may not be possible to guarantee the best possible trajectory, but as long as I can compute a decent, reasonable looking trajectory, the rest can be left up to the user (if a user isn't happy with a trajectory they could plot it in many steps for example).
My quandary really is how to combine the velocity math with the position math. It's easy enough to calculate the turns and thruster firing which will change one velocity to another (simple vector addition/subtraction), and it doesn't seem terribly difficult to figure out how to get a ship with a certain velocity from one point to another (more relatively simple vector math).
Any thoughts/suggestions/references would be much appreciated.
Thanks!
The spaceships:
- Have a set turning speed (radians/sec, different ships may be able to turn faster or slower)
- Have a maximum speed (not realistic for space, but better for video games)
- Have thrusters which only provide thrust in a limited number of fixed directions. Most likely only forwards or only forwards and backwards.
- The spaceships will have inertia, and there will be no friction acting on them
- There will be no (predictable) forces acting on the spaceship other than the thrusters, no gravity, etc.
- The mass/inertia of the ship doesn't change ever
The User will specify where they want their spaceship to end up, and the heading and speed they want to have when their ship arrives at the destination. So I need to take an initial position and velocity, a final position and velocity, and generate a set of turns and thruster firings that will deliver the ship to the final position at the correct velocity.
So what I need to figure out is how to actually compute the best trajectory, when to turn, when to thrust, etc. It may not be possible to guarantee the best possible trajectory, but as long as I can compute a decent, reasonable looking trajectory, the rest can be left up to the user (if a user isn't happy with a trajectory they could plot it in many steps for example).
My quandary really is how to combine the velocity math with the position math. It's easy enough to calculate the turns and thruster firing which will change one velocity to another (simple vector addition/subtraction), and it doesn't seem terribly difficult to figure out how to get a ship with a certain velocity from one point to another (more relatively simple vector math).
Any thoughts/suggestions/references would be much appreciated.
Thanks!