Path around a rotating square

0 favourites
  • 6 posts
From the Asset Store
*** 2D top down animated rotating trap game asset ***
  • 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!

  • 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

  • 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).

  • 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.

    [quote:ycvgommh]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:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)