- Home /
Trying to rotate something relative to camera the same way something else is rotated relative to the player
It's really confusing me. Here's what I thought should work- or rather the latest of several failed attempts:
var relativeRot : Quaternion = headPos.rotation.LookRotation(targetedModel.forward,targetedModel.up);
modelFruit.rotation = transform.rotation * relativeRot;
"modelFruit" is the transform of an object fixed to the camera, "transform" is the overlaid scope the model fruit and my script are attached to, "targetedModel" is the transform of the actual fruit object in the scene, and "headPos" is the transform of the player in the scene.
I was trying to get it so that the object in the scope is rotated the way it would appear to be rotated if you were looking at it from the player's point of view, but I can't see how to convert that into Quaternion functions.
Answer by rutter · May 16, 2012 at 09:10 PM
If your objects are parented in roughly the same manner, you might find it easier to work with the localRotation property of their transforms.
If you're lucky, this may be as simple as reading one and assigning it directly to the other. If not, you can probably do more or less the same plus some offset. At the very least, you can probably compare differences across frames, to make sure that one object rotates as the other does.
localRotation would work if the targeted object in the scene were a child of the player transform, but that isn't the case- they're both loose in world space.
I think I want something like:
modelFruit.localRotation = headPos.rotation.InverseTransformRotation(targeted$$anonymous$$odelRotation);
unfortuanately, Quaternion.InverseTransformRotation is not actually a thing.
Your answer
Follow this Question
Related Questions
Rotate object with quaternion to direction points 1 Answer
My LookRotation forces my character to snap back, and face starting direction after I stop moving? 2 Answers
Lookat, FromToRotation and LookRotation? 3 Answers
Need help with rotation 4 Answers
Spawning objects to the surface of a spehere correctly. 0 Answers