Trouble Rotating Points around Pivot

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.

Spiney! The magic you want (for each of your lines 5 and 6 in your top code blob above) needs to be this:

  • compute the difference from tangent to this anchor (Vector3)

  • rotate that difference / delta by the rotation

  • set the position of the tangent to now be the anchor plus the rotated vector.

I think I said that correctly.

Let’s just go with center and tangent Transforms

Vector3 difference = tangent.position - center.position;

Quaternion rotation ... (however you get this rotation of the center)

Vector3 rotatedDifference = rotation * difference;

tangent.position = center.position + rotatedDifference;

You would do that or each one independently, obviously.

1 Like

I’m a bit confused. Haven’t you defined your tangents in local space of that gameobject? At least that would make the most sense. So you don’t need to rotate them manually as they would rotate with the gameobject. You just need to transform them into worldspace when you want to use them. Do you actually want free moving tangents? So that you can break the path? Usual splines would always ensure that the in tangent has the same direction (actually opposite) as the out tangent.

At least in that tutorial p0 and p1 are local space positions and tranformed with TransformPoint. So they are naturally transformed with the object they belong to. Maybe I didn’t get the full picture. Though you haven’t shown the code of your spline point object. In the tutorial the the points are always local points. So a spline point would be one gameobject and the two tangents are just local space positions that rotate automatically with the gameobject. Since you said you get double the rotation amount that would be a sign that you manually rotate them and also get the rotation naturally from the local to world conversion.

1 Like

My word I’m daft. I did not realise that having the tangents local to the pivot would also account for rotation!

I don’t actually need to code anything. That’s a bloody change of pace for once.

1 Like