Quaterinon.Euler(0,0,somevalue) has no effect when rotating around a point
I'm doing a Yaw-Pitch-Roll type moving a gameobject around a pivot.
I'm using a RotatePointAroundPivot
function (taken from this forum)
private Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
{
Vector3 dir = point - pivot; // get point direction relative to pivot
dir = Quaternion.Euler(angles) * dir; // rotate it
point = dir + pivot; // calculate rotated point
return point; // return it
}
Any combination of Pitch or Yaw (angles.x or angles.y) works fine but Roll (angles.z) has no effect.
Can anyone explain? help me? etc.
Answer by TBruce · Apr 13, 2016 at 05:54 PM
@garrilla Have you considered using Transform.RotateAround()? But instead of using Vector3.zero you can replace it with the position of your object which I am assuming here is the Vector3 point.
And if this is not what you are looking for take a look at this link Yaw-Pitch-Roll.
Thanks @$$anonymous$$avina Yea, you're right on the point being the object...
I thought about rotateAround() but it doesn't really do what I'm wanting because my rotation might be (45, 135, 270) to pick three randomish numbers
Imagine the pivot is the center of sphere, and then I'm rotating the object around the surface of the sphere... so I want all three rotations at once
For the yaw and $$anonymous$$ch it works fine, but not the roll. which is just puzzling to me.
Did you exa$$anonymous$$e the Yaw-$$anonymous$$ch-Roll script in the provided link? Your script passes
Sorry, yes I have seen the blog.
It doesn't help directly in that it is yaw-pitch-rolling about the object's center, when I want to yaw pitch and roll around an offset pivot point... although I have had an alternative based on that approach that produces the same result - really what is different is that it assigns the Euler Angles directly rather calculating them with the Eurler method.
Another solution I tried was to apply the go.transform.RotateAround(myPosition, Vector3.forward, myEuler.z);
which a rolls the object around the pivot but also around it's center, which is not the effect I want.
Thanks!
Your answer
Follow this Question
Related Questions
Why Quaternion.Euler can't rotate 360 Degrees 0 Answers
Roll cuboid does not work properly 1 Answer
Change pivot point of gameobject 5 Answers
Reversed Rotation Problem 1 Answer