Auto following and recerse path

0 favourites
  • 6 posts
From the Asset Store
game inspired by auto chess , with soulslike combat
  • Hi there, I want to create the effect of an object moving along a predetermined path and then reversing and going back the way it came like a boor opening and closing but you have to time your move.. or going along a path then once at the end reverses back to the beginning, rinse and repeat..

    Any advice would be great..

    Thanks

  • Your object will need a boolean variable like isArrived

    False : Not reaching Destination yet, moving to Destination.

    True : Already reached Destination and coming back to Starting Point.

  • please explain the Boolean operation you mention.. Im still in the drag and drop phase..

    Thanks

  • The boolean it will work like a trigger to check your object reach destination or not.

    If No : Go from A to B

    If Yes : Go back from B to A

    This is my example for this : drive.google.com/open

    If you have any question please contact with me through Skype : dongnguyen602

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There isn’t a way to make a path in the editor, but as one possible solution you could place a bunch of sprite instances along a path and use that.

    Create a sprite and call it “node.” Give it and instance variable called “order.”

    Now just make multiple instances of node and position them in the shape of the path you want. Then set the order variables for each instance. 1 for the start, 2 for the second and so on. This is so we can move along them in order.

    Next we need to setup the object that will move along the path. Create a sprite and call it “follower.” Give it some instance variables:

    pos=0 for it’s position on the path

    speed=10 for the speed along the path.

    Anyways on to the events to make follower to move back and forth along the nodes:

    Every tick

    — follower: add self.speed*dt to pos

    Follower: pos<0

    — follower: set pos to 0

    — follower: set speed to -self.speed

    Follower: pos>node.count-1

    — follower: set pos to node.count-1

    — follower: set speed to -self.speed

    Global number t=0

    Global number id1=0

    Global number id2=0

    For each node ordered by node.order ascending

    — follower: pos<=loopindex

    —— set id1 to node.iid

    — follower: pos>=loopindex

    —— set id2 to node.iid

    ——stop loop

    Every tick

    — set t to follower.pos-int(follower.pos)

    — follower: set x to lerp(node(id1).x, node(id2).x, t)

    — follower: set y to lerp(node(id1).y, node(id2).y, t)

    That will change the followers pos variable with the speed. If it goes off either end then the speed is reversed and the pos is limited to the end.

    Next we loop over the nodes to find the instance right before and right after the object’s current pos.

    Finally we use lerp to get an actual xy position between those nodes.

    Note:

    Speed is how fast the follower moves from node to node. So for consistent speed keep the nodes evenly spaced.

    The events were done with only one path and one follower in mind.

    Barring any typos the above should work.

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