- Home /
Question by
pierscoe1 · Nov 30, 2014 at 06:09 PM ·
quaternionlock
Gimbal lock - object moving on surface of sphere
Hello,
I have an object moving on the surface of a sphere, but it gets stuck in what looks like gimbal lock when it reaches the north pole...
I thought my code should avoid this, as it's using all quaternions... but I've obviously messed something up somewhere :-/
here's what I've got so far:
var relativePos = transform.position - Vector3.zero;
var rotation = Quaternion.LookRotation(-relativePos);
rotation *= Quaternion.AngleAxis(-90, Vector3.right);
transform.rotation = rotation;
if (Physics.Raycast (transform.position, -transform.up, groundHit, 100)) {
transform.position = groundHit.point * 1.01;
transform.position += (transform.forward * speed * Time.deltaTime);
}
Comment