Thorny Newtonian motion of a spaceship

AI Thread Summary
Programming realistic spaceship motion in a 2D game involves complex calculations, particularly when the ship is already in motion. Key challenges include correcting for initial velocity when selecting a new destination and determining the optimal point to begin deceleration to ensure the ship stops at the target. The discussion highlights the need to consider both acceleration and deceleration vectors, as well as the ship's orientation during these phases. Suggestions include breaking down the problem into smaller segments and potentially using a physics engine for easier calculations. Ultimately, finding a balance between realism and playability is crucial for game development.
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!
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'Collision of a bullet on a rod-string system: query'
In this question, I have a question. I am NOT trying to solve it, but it is just a conceptual question. Consider the point on the rod, which connects the string and the rod. My question: just before and after the collision, is ANGULAR momentum CONSERVED about this point? Lets call the point which connects the string and rod as P. Why am I asking this? : it is clear from the scenario that the point of concern, which connects the string and the rod, moves in a circular path due to the string...
Thread 'A cylinder connected to a hanging mass'
Let's declare that for the cylinder, mass = M = 10 kg Radius = R = 4 m For the wall and the floor, Friction coeff = ##\mu## = 0.5 For the hanging mass, mass = m = 11 kg First, we divide the force according to their respective plane (x and y thing, correct me if I'm wrong) and according to which, cylinder or the hanging mass, they're working on. Force on the hanging mass $$mg - T = ma$$ Force(Cylinder) on y $$N_f + f_w - Mg = 0$$ Force(Cylinder) on x $$T + f_f - N_w = Ma$$ There's also...
Back
Top