# Path around a rotating square

Discuss game development design and post your game ideas

### » Tue Jun 16, 2015 5:31 pm

Hi everyone,

I'm having trouble remembering the formula to adjust the position of an object based on the rotation of another.

My current method is this; I have nodes set around the square itself to identify the 4 points I want to object to move to. I'm moving the object using the MoveTo plugin. Once the object reaches a node it's destination is set to the next node. This works well except for when the square rotates. The movement isn't smooth as it's simply following a straight-line path to the next node and not adjusting for the square's rotation.

The problem is I can't think of the formula I need to use to adjust the object's position based on the rotation of the square. Any help?

Here's the example (You'll need to click the black circle as the object in reference rotates around it. Once it hits the square you'll see what I mean):
https://dl.dropboxusercontent.com/u/47512624/games/Public/Love%20Triangle/Love%20Triangle%20-%20Proto/index.html

Thanks!
Last edited by eochranek on Tue Jun 16, 2015 7:14 pm, edited 2 times in total.
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

### » Tue Jun 16, 2015 6:31 pm

You could just move around the unrotated nodes, but keep the circle invisible. Then have another visible sprite that you set:

sprite: set position to square
sprite: move circle.x-square.x pixels at square.angle
sprite: move circle.y-square.y pixels at square.angle+90
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

### » Tue Jun 16, 2015 7:16 pm

I'm not sure I follow. Take a look at my link again, and click on the black circle to make the object rotating fly into the square. Once it hits the square the square will start to rotate (and the object changes into a square as well).
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

### » Tue Jun 16, 2015 8:46 pm

Yeah, my solution is very incomplete. I don't know exactly how the the moveto behavior operates to make a recommendation. Personally I'd opt to do the motion with just events instead of working around the behaviors, but it's likely not useful since it would be incompatible with what you may had.

The problem is I can't think of the formula I need to use to adjust the object's position based on the rotation of the square. Any help?

If you want the math to rotate an object around a point here's a post with the math for that:
viewtopic.php?f=147&t=146141&p=935879#p935879
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514

### » Wed Jun 17, 2015 3:48 pm

Ah that's cool. The MoveTo basically makes an object move to a specific point. It was the only way I could the object to change nodes once it reach a specific X,Y coord.
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

### » Thu Jun 18, 2015 4:37 am

I meant how the behavior actually moves the object. The two ways I can think of off hand would be either it calculates a distance and angle an repeatedly moves and decreases the distance, or it continuously moves toward a point at a constant speed. It doesn't matter either way since it just moves to a stationary point. It can't handle a moving point.

One way you possibly could use the behavior would be to use the move to behavior to advance to the next node and then every tick manually rotate the square and use that equation to rotate the object with the square.
B
101
S
39
G
134
Posts: 5,588
Reputation: 85,514