How to Tilt a Spaceship Based on Inertia/Acceleration Force Separate from Facing Direction?


  • 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:

Try separating the problem into two distinct scripts.

  1. Place the object you want to tilt in a game object and call it "Ship".
  2. Place "Ship" in a parent game object and call it "Ship Facing Camera".
  3. Place tilt rotation in a script attached to "Ship" and make them use local transform.
  4. 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.

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;