x


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.

more ▼

asked May 16 '12 at 07:53 PM

Kiloblargh gravatar image

Kiloblargh
1k 33 54 70

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

1 answer: sort voted first

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.

more ▼

answered May 16 '12 at 09:10 PM

rutter gravatar image

rutter
5.2k 2 11

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(targetedModelRotation);

unfortuanately, Quaternion.InverseTransformRotation is not actually a thing.

May 17 '12 at 01:01 AM Kiloblargh
(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:

x439
x83
x39
x5
x1

asked: May 16 '12 at 07:53 PM

Seen: 566 times

Last Updated: May 17 '12 at 01:03 AM