Rotating compass

I have a physics object that has a rotating pointer part-- it rotates on the z axis to a fixed point in the scene-- however, when I apply physics to the object it’s attached to it won’t rotate properly. It moves fine with the object, and still points to where it’s supposed to, but it won’t rotate with the object-- it stays level.

Even if physics is not applied and I simply rotate it in the editor, the pointer still stays level in the scene. What am I missing?

Hey @wolfear87! So I believe the reason it isn’t rotating at all is because the component Set World Location and rotation are setting the full rotational values every tick. So the rotational values every time this goes through are being set as your generated X, but Y and Z are always going to be reset to 0 so the only thing on the gyroscope that will shift currently is the X, and only Z for the pointer. With your current implementation you’d have to pass in where you want it to rotate to, or get the currents rots and pass them through so that it doesn’t get set to 0 every time. Let me know if you have any questions!

1 Like

Ok, totally understand why it’s setting to zero, but unclear on how to fix/get the current rotations. If I use get world rotation for the pointer and pass it through, it still doesn’t work. should the set up be different?

As of now we can move the full compass itself along with it’s parent.
2022-08-06_20-21-18

So basically, if I understand correctly, you’re attempting to more or less have the compass body/gyro be freely able to rotate instead of being level, and want the compass needle to stay with it but continue attempting to point as north as it can while constrained to the local rotations of the gyro. If so we’d have to change the way you’re going at this, as of now.

With the current implementation, this would mean we would need to either figure out the math to do a local rotation to the side of the compass that is closest to north if the base gets rotated in any form vertically.

Or, we have to do the math to point it in world space to keep it’s rotations tied to the same as it’s parent, which makes this a bit more complicated than initially thought.

I might have to write something up a bit different soon!

I think I’ve got it, I changed from world rotation to relative rotation, it seems to be working so far, the needle is moving/rotating with its parent while still rotating on the z toward a fixed point. If my math seems correct

Ahh great implementation, you got it! For anything that will have to rotate but maintain it’s relativity with their parent, always best to go with local rotations. Thanks for posting!

Why do you multiply by -1?