Thorny Newtonian motion of a spaceship

Click For Summary
SUMMARY

The discussion centers on programming realistic spaceship motion in a 2D game, focusing on the complexities of Newtonian physics. Key variables include initial velocity components (V0x, V0y), destination coordinates (Dx, Dy), and acceleration (a) with a deceleration ratio (r). The challenge lies in calculating the correct trajectory and timing for acceleration and deceleration, particularly when the ship is already in motion. Suggested solutions include breaking the problem into smaller segments and considering the use of a physics engine to simplify calculations.

PREREQUISITES
  • Understanding of Newtonian physics principles
  • Familiarity with 2D game development concepts
  • Knowledge of vector mathematics and components
  • Experience with programming languages suitable for game development (e.g., C#, JavaScript)
NEXT STEPS
  • Research "2D physics engines" such as Box2D or Unity's built-in physics
  • Learn about "vector mathematics" for game development
  • Explore "trajectory calculations" in physics for motion prediction
  • Investigate "frame of reference" transformations in game physics
USEFUL FOR

Game developers, particularly those focused on physics-based simulations, and programmers looking to implement realistic motion mechanics in 2D environments.

LiquidPenguin
Hi, I am programming a game that involves controlling spaceships with a top-down 2d dimensional view. I want this game to have as realistic a physics model as possible. The idea is that you select a ship and then click on a destination. The ship then turns to an appropriate heading (turning is also acceleration/velocity based movement), turns on the thrusters to accelerate, at some point turns off the thrusters and begins decelerating through retrorockets, and then, when decel is complete, comes to a complete stop at the clicked location.

Now, the problem really isn't that hard unless the ship is already moving when you select a destination. In THAT case it becomes (to me) a hellish convolution of time-based variables. You have to correct for the initial velocity that is normal to the path towards the target by angling the ship slightly in the opposite direction. But, even if you can calculate that adjusted heading, while you are rotating the ship to that angle your position has changed because of your initial velocity, and the angle is all wrong.

Also very thorny is calculating the point at which, after accelerating, you should begin decelerating. All velocity has to be canceled by the end of the deceleration. Because the ship's retrorockets are mounted opposite the thrusters, the deceleration vector will always be the inverse of the acceleration vector, multiplied by a constant that is the ratio of deceleration over acceleration. Which, I think, means that all of the initial velocity that is normal to the path of flight must be canceled by the end of the acceleration phase (otherwise the decel phase would increase this velocity, throwing us off course). But doesn't that mean that it will be necessary to rotate the ship during the accel phase so that, by the beginning of decel, the ship is facing directly towards the target destination (though it began accel at a slightly skewed angle to compensate for normal velocity)? Again, the velocity at the destination must be zero in all directions.

The acceleration components will be changing by the sin and cos of the heading... which makes the equations more and more complicated. Should I be employing calculus here? How can I calculate the point at which to begin decelerating? I've made many many many equations trying to get that, but they all seem to be dependent on some other factor (such as the time of the accel burn plus the decel burn) that is in reality dependent on the very result I'm trying to find. Let me summarize what constants are known to the program (I don't know what the convention is for variable names, so please excuse my mistakes in that regard):

Dx, Dy: Destination position
Sx, Sy: Start Position
V0x, V0y: Initial Velocity Components
Theta: Ship's heading
a: max magnitude of ship's acceleration
r: ratio of deceleration rate / acceleration rate
V0r: Initial rotational velocity
Ra: Max rotational acceleration (deceleration is the same)

So since the "start location" is actually changing over time due to the initial velocity (Sx(t)=Sxi+V0x*t), the displacement that will get us to our destination is also changing. Arg.

One big thing that I am not sure of is whether to calculate all the vectors in frame of reference of the standard axes or the frame of reference of the direct line to the destination. For instance, do I look at the initial velocity as V0 in the x and y directions, or velocities normal and parallel to the desired direction? I've tried both ways, and I only run into either dead ends or end up right where I started. Obviously, the problem is not intractable, I mean they must have done the same problem in 3 dimensions and accounting for gravity and a million other factors for the apollo missions. But it's certainly causing me severe pain. Any insights anyone can provide, or mistakes in my logic, would be gratefully appreciated. Thanks for reading.

-Geoff
 
Physics news on Phys.org


Hi Geoff,

It sounds like you have a very complex and challenging problem on your hands! Calculating the motion of a spaceship in a game with realistic physics is no easy task. It's great that you are striving for accuracy and realism in your game, but it's also important to remember that at the end of the day, it is still just a game and some simplifications and approximations may be necessary to make it playable.

That being said, let's dive into some possible solutions for your problem. One approach could be to break down the problem into smaller, more manageable pieces. For example, instead of trying to calculate the entire trajectory of the spaceship at once, you could break it down into smaller segments, such as calculating the initial velocity, then the acceleration, then the deceleration, and so on. This could help simplify the equations and make it easier to account for changing variables.

Another approach could be to use a physics engine or library that already has built-in functions for calculating motion and collisions. This could save you a lot of time and effort in trying to figure out the equations yourself.

As for the frame of reference, it may be helpful to use the frame of reference of the spaceship itself. This would allow you to easily calculate the components of the velocity and acceleration in the direction of the spaceship's heading. However, it's always good to experiment and try different approaches to see which one gives you the most accurate results.

In terms of whether or not to use calculus, it really depends on the level of accuracy and realism you want to achieve. Calculus can be useful in calculating instantaneous changes in velocity and acceleration, but it may not be necessary if you are willing to make some simplifications.

Overall, it's important to keep in mind that there may not be a single "correct" solution to your problem. It's a complex and dynamic system, and different approaches may work better in different situations. Keep experimenting and don't be afraid to make adjustments along the way. Good luck with your game!
 

Similar threads

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