MoveTo, Wait, MoveTo, Wait, Repeat

Get help using Construct 2

Post » Sat Mar 02, 2013 1:21 am

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.
B
11
S
3
G
1
Posts: 23
Reputation: 1,615

Post » Sat Mar 02, 2013 1:37 am

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.
B
6
S
1
Posts: 67
Reputation: 986

Post » Sat Mar 02, 2013 8:10 pm

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?
B
11
S
3
G
1
Posts: 23
Reputation: 1,615

Post » Sat Mar 02, 2013 10:49 pm

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.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Sat Mar 02, 2013 11:06 pm

@mattb Why do you have *dt in the move block? I was under the impression that this was baked into the sprite movements?
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Sun Mar 03, 2013 10:29 am

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.
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Sun Mar 03, 2013 10:40 pm

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.
B
11
S
3
G
1
Posts: 23
Reputation: 1,615

Post » Sun Mar 03, 2013 10:45 pm

Also, thanks Mattb for introducing me to instance variables. I have never used them before. Super powefull!!!
B
11
S
3
G
1
Posts: 23
Reputation: 1,615

Post » Sun Apr 14, 2013 6:32 am

@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
B
7
S
1
G
3
Posts: 7
Reputation: 3,035

Post » Mon Apr 15, 2013 4:00 pm

@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
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Next

Return to How do I....?

Who is online

Users browsing this forum: Braus and 9 guests