MovingTarget.cs doesn't move the hoop correctly if it's rotated

Hello!
The code in MovingTarget.cs has this code:

    var x = magnitude * Mathf.Cos(Time.time / timePerCycle * 2 * Mathf.PI);
    transform.position = initialPosition + Vector3.left * x;

The hoop moved sideways as expected, until I rotated the hoop instead of my camera to make sure my camera continued to show a particularly appealing portion of a skybox.

When I select the hoop and click the Global | Local button, the angle gizmo changes. Vector3.left seems to move the hoop according to the global angle. How do I make it move left according to the local angle?

Have you ever puzzled over something for an hour, finally given in and posted a question, and then (possibly due to having to put your issue into words), promptly discovered the solution?

    var x = magnitude * Mathf.Cos(Time.time / timePerCycle * 2 * Mathf.PI);
    transform.position = initialPosition + transform.right * x;

:face_with_raised_eyebrow:

Privacy & Terms