x


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

more ▼

asked Feb 19 '10 at 09:36 AM

Absyss gravatar image

Absyss
13 1 1 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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 gravatar image

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
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 19 '10 at 09:54 AM

Statement gravatar image

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
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

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