- fryzoy
- Sep 21, 2005
-
What.
|
FBz posted:
I've decided to dive back into XNA again and mess about with it again, but this time in 3D.
I have a spaceship (one of the models you are given with the SDK) and I have it moving around in 3D space quite well. You point it in any direction (up/down/left/right/back/fourth etc.) and it flies along that vector, I've implemented quat’s for proper rotations and all that jazz. What I'd like to do is add proper acceleration. At the moment it accelerates along the vector until it hits full speed, but when you turn it just flies off in that direction instantly, which doesn't really happen in the real world. What I'd like is smoother turning and acceleration, ie. It flies off in one direction then when you turn somewhere else and hit the thrusters again instead of insta-accelerating it gradually gets into its new vector. I have implemented something that half does this but it's totally wrong as it doesn't work 100% of the time. I've tried looking up how to do this but I am blinded by science and formulas and I am not sure how to implement it at all.
What I have so far is:
A vector in which the ship is currently moving (momentum I guess)
A Vector which the ship is pointing in
Current thrust level (could be zero, leaving the ship to 'float' on it's current vector)
I am guessing I need to go from the momentum vector to the new direction vector based on the amount of thrust, but I don't know how.
If someone can tell me how to implement acceleration or point me to a good tutorial (I've looked at loads but most are either 2D and I can't figure out how to translate that to 3D, or they just ramble on about something quite unhelpful) I'd be most grateful. I think I really need an example or it spelt out in English with little words that I can understand
As long as I am not totally misunderstanding you, you should be fine with adding the product of the direction vector (normalized) and thrust scalar to your momentum vector.
So let's say you have D, your direction vector, V, your momentum vector and a your accelleration force scalar, you'd then do D = D + V * a.
|
#
¿
Jan 4, 2008 13:38
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 7, 2024 20:01
|
|
- fryzoy
- Sep 21, 2005
-
What.
|
TSDK posted:
Nope, D is the constant here and it's V you want to update. For simple newtonian mechanics using euler integration:
D - Ship's forward vector
V - Ship's current velocity
F - Thrust
m - Mass of ship
dt - Timestep
a = F/m
V' = V + D*a/dt
Oh yeah that was retarded; I mean that.
|
#
¿
Jan 5, 2008 18:42
|
|