Hey guys, just trying to work out exactly how to apply Newton's laws of motion etc, to a Spaceship. I've made games where I've faked it all before, however this time I want to use something a bit more realistic. But to also include another object hitting said spaceship and changing it's direction, plus also having a stars gravity pull it as well etc.
So what I presume this should look like is something like this for basic movement;
public void MoveInDirection(float deltaTime)
{
float power = ?;
Vector2 force = direction * power;
float mass = 1000.0f; // 1000kg in this case
Vector2 acceleration = force / mass;
Vector2 velocity = acceleration * deltaTime;
position += velocity;
}
Now the part I'm a little confused with, is where I should be adding my delta/elapsed time. Should I only be adding it to the velocity, not at all or somewhere else to simulate the movement? And as for power, what sort of input would I need to give it to move a 1,000kg object etc.
As the power input, I presume it needs something else behind it, as in, to generate it from 0 up to a max power. So we don't just instantly go max speed. So some form of coefficient with a limiter etc?
And lastly if I have say a projectile hit the ship. I presume I should be doing something like adding that projectiles force by doing this to the previous function in the post:
Vector2 force = direction * power;
force += projectileForce * projectilePower;
To the previous function in the post. So that way we incorporate another objects force to our own. But then slowly dampen it till it's effect wears off etc.
Any lastly how would I add in gravity to this function, so I can have this object being slowly pulled to the gravity's source.
I should know all this stuff, but after not programming or doing math for a couple of years, I can't believe how rusty I feel in some areas
Cheers,
Scott