- Home /
How to Tilt a Spaceship Based on Inertia/Acceleration Force Separate from Facing Direction?
Situation:
- the game is a dop down perspektive ( bird view )
- i have a PlayerObject (Spaceship) that always faces the Mouse ( transform.rotation.y )
- and a up/down/left/right movement ( rigidbody.velocity.z & x )
- inertia is visualized with X/Y Rotation ( transform.rotation.x & z )
What i need:
- i dont want the tilting (inertia) in the looking direction BUT in the movement direction
I think a good example is a Hoverboat that can slide sidewards but inertia forces apply still in movement direction ...
here is a shematic: http://i238.photobucket.com/albums/ff160/absyss/_Q_RotateMove.gif
Answer by runevision · Feb 19, 2010 at 10:16 AM
Maybe you can use this:
// Rotation to face the mouse. // (Calculation of yRotationToFaceMouse is not covered here.) Quaternion rot = Quaternion.Euler(0, yRotationToFaceMouse, 0);
// Find the axis we want to tilt around. // It should be perpendicular to the velocity and to the up direction. Vector3 tiltAxis = Vector3.Cross(Vector3.up, rigidbody.velocity);
// Now rotate the existing rotation by tiltAmount around tiltAxis. // (Calculation of tiltAmount is not covered here.) rot = Quaternion.AngleAxis(tiltAmount, tiltAxis) * rot;
that works perfectly thanks! Just a typo to correct: "Vector3.Cross"
Answer by Statement · Feb 19, 2010 at 09:54 AM
Try separating the problem into two distinct scripts.
- Place the object you want to tilt in a game object and call it "Ship".
- Place "Ship" in a parent game object and call it "Ship Facing Camera".
- Place tilt rotation in a script attached to "Ship" and make them use local transform.
- Place movement and facing camera rotation in a script attached to "Ship Facing Camera".
That way you get the benefits of having two separate transforms to work with, essentially reducing the maths needed to calculate tilt. Now you can apply tilt with local coordinates, and don't have to worry about any other rotations because parents do that for you.
yes i have thought of this solution before but i wanted to combine both rotations into one calculation.