x


RotateAround and Gimbal lock

Hi guys, I know there is plenty of post about this but I can't find any of those that fix our problem.

We have a basically a box that we want to rotate around a sphere just like it walk on it. We are using RotateAround to do so and it seems to work fine until we get to the other side of the sphere (we start on top of it). At this point, we seems to experiment the Gimbal lock problem. I thought Unity was already handling this with RotateAround but it doesn't looks like it.

//This part is done everytime there is an input
Vector2 deltaNorm = delta;
deltaNorm.Normalize();

Vector3 moveAxis = transform.TransformDirection(Vector3.right) * deltaNorm.y * -1.0f + transform.TransformDirection(Vector3.forward) * deltaNorm.x * 1.0f;
moveAxis.Normalize();

mMoveAxis = moveAxis;
mMoveAngle = delta.magnitude;

//This part is done in FixedUpdate()
transform.RotateAround(Vector3.zero, mMoveAxis, 1.0f * Time.deltaTime * mMoveAngle);
Vector3 newPosition = transform.position;
newPosition.Normalize();
transform.up = newPosition; 
newPosition *= sphereInitialRadius * sphere.localScale.x;
transform.position = newPosition;

Our box has a RigidBody.

So we want to know how to make the box go forward even when we are at the "bottom" of the sphere.

Thanks for you input

more ▼

asked Sep 02 '11 at 04:21 PM

cakeby gravatar image

cakeby
1 2 2 3

I'd draw a debug line for that mMoveAxis - are you certain it's right?

Sep 02 '11 at 10:26 PM Waz
(comments are locked)
10|3000 characters needed characters left

0 answers: sort newest
Be the first one to answer this question
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:

x87
x9

asked: Sep 02 '11 at 04:21 PM

Seen: 743 times

Last Updated: Sep 02 '11 at 10:26 PM