- Home /
How to do relativte offset rotation
I have two rotations in the form of vectors, in the start function I want to save the rotational offset between the vectors. The first vector is going to be the reference vector that a will use to get the second right. So I want to be able to keep the rotational offset between them during runtime
Don't know if I made it clear enough, hope you understand.
This is want i have tried:
void Start ()
{
avgFixerDir = xxx; //the on that will be correct during the runtime
mRotationOffset.SetFromToRotation(avgFixerDir.normalized, transform.forward);
}
voud Update()
{
newForward = (mRotationOffset * avgFixerDir.normalized); //trying to get forward to the same ralative offset as in the start
}
I'm having trouble visualizing exactly what you want here since I don't see the whole setup, but something like this will work. I think you want the parameter to SetFromToRotaton() to be reversed. Note my typical way to solve this kind of problem is to use an empty game object with my visible game object as a child. The visible object will have a local rotation with respect to the child, so I can have maintain the relative rotation.
The child thing is not possible, the avgFixerDir is something i calculate. But the offset rotation that I get in the start, can i keep that some how?
You code in some form should work. But I'm confused about how you have things setup. To me you would have two vectors in the beginning. You would have the forward vector and then the relative vector of the direction you really want, both having the position of the game object as the origin. Then you would calculate the rotation with the parameters flipped:
Quaternion q = mRotationOffset.SetFromToRotation(transform.forward, avgFixerDir.normalized);
Now you can do something like:
newVector = q * oldVector;
But I'm not sure that is how you have things setup. Is the reason you think you cannot do a child because you calculate avgFixerDir? If so, you can use a child. Just set transform.localRotation of your visible game object, and it will be rotated relative to the parent.
SetFromToRotation returns void, so that's not correct. I have no clue why this is not working :(
It is a class method, so it should be called with the class name:
Quaternion.FromToRotation(transform.forward, avgFixerDir.normalized);
Sorry I did not catch that. I'm not sure why it even compiles. What is the class of mRotationOffset?
Your answer
Follow this Question
Related Questions
Relative rotation offset? 2 Answers
Location in relation to other objects rotation 1 Answer
reproducing hingejoint.angle 0 Answers
Question about angles. 1 Answer
smooth look at with offset 0 Answers