#Using Quaternion.LookRotation() on a rotated child to point it at something in world space

1 messages · Page 1 of 1 (latest)

modern nebula
#

I am attempting to get a child-child that could be rotated to any angle(as can its parent) to look at something in world space, however lookrotation will only output the rotation on the global scale, and i have no idea how to translate/correct this into a rotation that would get the child to rotate correctly and point at the point in world space without being offset by the overall child-parent rotation

supple sluice
#

However you need to rotate the child last, because parent rotations affect the child

#

Also there's Transform.LookAt which does the same thing as setting its rotation to a LookRotation

modern nebula
#

Dont have access to a Transform(entities all the way down) and all im doing is rotating the child

opal quartz
#

If you know the rotation of your parent, you can invert it to correct your own rotation

#

Quaternion.Inverse(parentRotation) * childRotation;

#

(and Mathematics also has a quaternion inverse method; i just don't remember the exact name off the top of my head)

modern nebula
#

Could have sworn i tried that to no avail

modern nebula
#

yeah, nothing changes adding Quaternion.Inverse(parentRotation) to the mix

#

                    float3 TargetPoint = math.normalize(TargetPosition - WorldPosition);
                    Quaternion TargetRotation = Quaternion.LookRotation(TargetPoint, Vector3.up);
                    //rotate
                    currentRotation = Quaternion.Lerp(currentRotation, TargetRotation, 1);

                    ref LocalTransform Transform0 = ref componentLookupLocalTransform.GetRefRW(Entities[0]).ValueRW;
                    ref LocalTransform Transform1 = ref componentLookupLocalTransform.GetRefRW(Entities[1]).ValueRW;

                    Transform0.Rotation = Quaternion.Euler(0, currentRotation.eulerAngles.y, 0) * Quaternion.Inverse(parentLocalTransform.Rotation);
                    Transform1.Rotation = Quaternion.Euler(currentRotation.eulerAngles.x, currentRotation.eulerAngles.y, 0) * Quaternion.Inverse(parentLocalTransform.Rotation);

                    aComponent.CurrentClientRotation = currentTurretRotation;

is what the current mess looks like, with the suggestion slapped on

opal quartz
#

Quaternion multiplication isn't commutative. You have it the wrong way round.

#

I would've expected to see some change, though

#

you'd need to know the world rotation of your parent, not the local rotation

modern nebula
opal quartz
#

parentLocationTransform.Rotation sure sounds like a local-space rotation 😉

#

That only tells you the rotation of the parent relative to your grandparent

modern nebula
#

ok turns out i was using the rotation of the overall parent which explains the no change