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

 0 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 more ▼ asked Feb 19 '10 at 09:36 AM Absyss 13 ● 1 ● 1 ● 5 runevision ♦♦ 8.1k ● 29 ● 46 ● 112 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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; `````` more ▼ answered Feb 19 '10 at 10:16 AM runevision ♦♦ 8.1k ● 29 ● 46 ● 112 that works perfectly thanks! Just a typo to correct: "Vector3.Cross" Feb 19 '10 at 12:25 PM Absyss add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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. more ▼ answered Feb 19 '10 at 09:54 AM Statement ♦♦ 20.2k ● 35 ● 71 ● 176 yes i have thought of this solution before but i wanted to combine both rotations into one calculation. Feb 19 '10 at 12:28 PM Absyss PS: i might use this for other puposes though Feb 19 '10 at 12:28 PM Absyss add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1948
x1862
x1425
x99
x21

asked: Feb 19 '10 at 09:36 AM

Seen: 3178 times

Last Updated: Feb 19 '10 at 12:44 PM