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
#Using Quaternion.LookRotation() on a rotated child to point it at something in world space
1 messages · Page 1 of 1 (latest)
Just set the child's transform.rotation. That is the global rotation
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
Dont have access to a Transform(entities all the way down) and all im doing is rotating the child
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)
Could have sworn i tried that to no avail
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
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
all i have that i know about is the rotation of the parent entity(which is technically a child but it isint rotated in this case) so it in theory should be the world rotation, unless i have something wrong there and should dig into localtoworld for that
parentLocationTransform.Rotation sure sounds like a local-space rotation 😉
That only tells you the rotation of the parent relative to your grandparent
ok turns out i was using the rotation of the overall parent which explains the no change