How to move a character smoothly around a rotating rectangle?

Hi! I’m working on a game where the player controls a box character that moves around the sides of a rectangle. The rectangle (or “center block”) can rotate, and I want the character to stay aligned and move smoothly along its perimeter—even as it rotates.

I’m not using the built-in “Rectangular Movement” behavior, because I want more control and rotation support. I’ve tried placing 4 points around the rectangle and moving the character between them, but I’m not sure if I’m doing it in the best way.

What’s the easiest and cleanest way to make this movement work—especially while allowing the rectangle and the path to rotate?

Thanks in advance!

You could look at putting points on each of the corners of the rectangle, and moving from point to point using lerp. That way the rotation of the rectangle won’t matter.

Something like this, where ratio is the distance from point1 to point2 as a value between 0 & 1:

image

1 Like