# How to do space physics with 3d spaceship spinning?

## Recommended Posts

Hi, I've got my spaceship in 3d. When the user presses left I yaw left on my ship. But what I also want to do is when they press left and take their finger off, the ship keeps spinning, ie space physics. I am rotating the ship by rotating its vertices around the ship's yAxis. ie rotating points around a line. So any ideas on how to keep the ship spinning? Thanks

##### Share on other sites
You could use the left and right keys to modify a yaw variable which contains the rate and direction of rotation; you'd then rotate the ship each frame based on that variable.

##### Share on other sites
But just say the ship's x,y,z axis are lined up with the world's axises.
And the ship is spinning on the yAxis(of the world and its own axises).

And then I decide to pitch the ship 30 degrees from what it was.

From what you are saying to do, the ship would now spin on a pitched angle of 30degrees(because of the yaw spinning), instead of just around the yAxis of the World like it was before pitching 30 degrees.

So basically I don't believe that would be proper space physics.
Correct me if I'm wrong.

Thanks

##### Share on other sites
It won't do that if you have variables for pitch, roll, and yaw and rotate the ship by them each time.

##### Share on other sites
I see, I sorta got that implemented, but it doesn't look right. Ill post screenshots later when I get home.

I thought maybe somehow I could have a direction vector + a speed variable to determine which way the ship is spinning, and how fast it is spinning.

Would that work? Right now I'm finding it hard to imagine how the ship is supposed to move/react with rotations.

Thanks

##### Share on other sites
well, im not maths expert (14, in algebra 1, but im teaching myself ^^) and i have a XRotV, XRot, YRotV, YRot, and ZRotV, ZRot, and every frame i add:
XRot += XRotV;
YRot += YRotV;
ZRot += ZRotV;

and i set the translation matrix to (XRot, YRot, ZRot) render, then move the the next object, set it to that objects (XRot, YRot, ZRot), etc.

and then i modify the *RotV variables on key presses, (with fancy sin/cos functions and stuffs :-D) and if i have friction, i multiply it by a friction fraction :-D anyway, i hope that helps

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628385
• Total Posts
2982391

• 10
• 9
• 15
• 24
• 11