So after following Catlike Coding’s old bezier curve tutorial I’ve been having fun making my own implementation, having each spline point being a separate game object, with the tangent points local to the world center point. So far the results are pretty Gucci:
The last feature I’d like to add in the editor implementation is being able to rotate the central point (rotating the game object itself) and have the two tangent points rotate around with it. However despite lots of googling the best result I can come up seems to rotate the two points around by double the amount I rotate by (the game object is rotated correctly).
So thus far I have:
public void SetCenterPointRotation(Quaternion rotation)
{
Quaternion transition = rotation * Quaternion.Inverse(transform.rotation);
ForwardTanget = transition * ForwardTanget;
BackwardTanget = transition * BackwardTanget;
transform.rotation = rotation;
}
Logic being, based on what I found via searching, I’d find the difference in the rotations - supposedly found by multiplying the final rotation by the inverse of the initial rotation - and rotate the tangents with that by means of the Quaternion * operator.
The above is called by this bit of editor code:
EditorGUI.BeginChangeCheck();
Quaternion rotation = Handles.RotationHandle(HandleRotation, point);
if (EditorGUI.EndChangeCheck() == true)
{
Undo.RecordObject(splineWaypoint, $"Rotated Spline of {splineWaypoint.name}");
Undo.RecordObject(splineTransform, $"Updated Transform of {splineWaypoint.name}");
EditorUtility.SetDirty(splineWaypoint);
splineWaypoint.SetCenterPointRotation(rotation);
}
The proper rotation handle is being hidden by this editor code as well.
I’m hoping there’s something small I’ve missed here, and any direction would be welcome. If the answer is very maths heavy… explain it to me like I’m a child because my mathematical knowledge doesn’t go far beyond the household stuff.