MoveTo, Wait, MoveTo, Wait, Repeat

0 favourites
  • 12 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • Hi Guys. This is my first question and I hope its not a dumb one.

    I am using the MoveTo behavior by Rexrainbow and what I am trying to do is move a sprite from one position to the next, wait for 2 seconds, move to another position, wait 2 seconds, move to another position, wait 2 seconds, move to the original location...and then have it repeat that behavior.

    I have a Sprite Object with the MoveTo behavior Activated with a Max Speed of 400. Original location 100,200.

    Actions include:

    Sprite - Set MoveTo target position to (700, 200)

    System - Wait 2 seconds

    Sprite - Set MoveTo target position to (700, 400)

    System - Wait 2 seconds

    Sprite - Set MoveTo target position to (100, 400)

    System - Wait 2 seconds

    Sprite - Set MoveTo target position to (100, 200)

    System - Wait 2 seconds

    ..so basically the sprites moves around in a rectangle (or wherever I set it to go)

    What I can't figure out is how to have the sprite repeat this behavior as long as the layout is displayed. And I don't know which event to use to start it(On layout start would only have it play once)

    Can anyone help a Construct 2 newbie out?

    I tried using System Repeat but that got ugly. Must be a simple way.

  • To have it repeat every 2 seconds indefinitely, the best way would be to remove that Wait command, create a variable to track it's position in the process, and run the event every 2 seconds using the "Every X seconds" event. Then just use the current state of the variable to decide which position the sprite should be move to each time it runs.

  • I'm eventually planning on varying the wait times, and moving the sprite to different locations and then playing an animation etc. What you suggested would work great for the example I gave but I just gave a simple scenario as an example.

    I'm really looking for an easy way to build background animation, or learn how to build cut scenes. I was hoping a combination of MoveTo and Waits (along with adding animation changes) would be a way to accomplish this but I still don't know what event to use to trigger it and to let it repeat forever. Am I going about this the wrong way with the Wait action?

  • hi alisa, here's a simple way of moving a sprite around with waypoints:

    https://dl.dropbox.com/u/52354372/waypoints.capx

    very basic, no acceleration or turning & the collisions are innacurate, but should be what you're after for simple background anims.

  • mattb Why do you have *dt in the move block? I was under the impression that this was baked into the sprite movements?

  • i'm also a C2 (& programming) newbie so the deltatime might be redundant, but i'm pretty sure it's needed so that the sprite moves at 'speed' pixels per second instead of per frame.

  • Thanks Mattb. That waypoint example is helpful food for thought. I never thought of just using the Is Moving and using collision events to redirect the sprite

    Have you tried the behavior plugin MoveTo at all? Just wondering.

  • Also, thanks Mattb for introducing me to instance variables. I have never used them before. Super powefull!!!

  • mattb - Really like your solution - but can I ask a followup? Anyone have any theories on you might make a sprite who's rounding the waypoints sensitive to the presence of a player - and respond? I'm thinking there's a patrolling guard moving between waypoints, who, either by line of sight, or proximity is alerted to the presence of the player and respond by moving toward.

    Then resuming the routine of rounding waypoints should nothing be found. It's doing my head in - there are many nice solutions in C2, but can't figure how to blend that waypoint-ing behaviour with a player detection/chase mechanism.

    Any thoughts would be most welcome...

    Cheers

  • ADenton - I think your first step before working out any event logic should be to clearly define states & behaviours for your guard, & think through every possibile situation for him.

    I would have the states (stored in the guard as a combination of bools or a single text variable) for a guard in a shooter game something like this:

    Patrol - walks between waypoints, relaxed posture; initial behaviour

    Patrol alert - walks between waypoints, combat pose; this behaviour triggered after being previously alerted, & could return to the initial patrol after a time.

    Suspicious - hears noise & stops patrolling; walks towards point of last noise; waits there for several seconds; if nothing found, walks to closest waypoint & state changes to 'patrol alert'

    Attack - has player line-of-sight, or saw player within eg. the last 10secs; runs at player & shoots; if player shoots back then run to nearest cover

    Alisa - yes I'm using MoveTo at the moment for some elevators, very handy behaviour

  • Alisa

    Try Zigzag behavior, it could define a square path very easily. (Even a hex path)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Rexrainbow! I'll give that a look!

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