# Have something happen for a limited amount of time

Get help using Construct 2

### » Sat Feb 01, 2014 6:01 pm

Hi!

What would be a good way to make an enemy walk left for say 5 seconds and after that walk right for five seconds?

I'm controlling the enemy currently with platform controls and on every tick -->simulate control -->left. I can't seem to figure out a good way of making it move for a limited time only.
B
9
S
1
Posts: 97
Reputation: 715

### » Sat Feb 01, 2014 6:25 pm

There are many different ways you could do this and it's probably worth checking through the FAQ and doing a forum search to see how other people would solve this.

For me, I would give my enemy a Boolean variable WalkingRight and put a couple of invisible obstacles on the layout where I want the enemy to change direction. I would give my obstacles each a Boolean variable as well, something like ChangeToWalkLeft - the obstacle on the right would then have this set to true and the one on the left set to false (this prevents double collisions giving you problems later).

Then in the event sheet, the enemy controls would be:
- if enemy.WalkingRight = true ; simulate platform press right
- if enemy.WalkingRight = false ; simulate platform press left

-> On enemy collision with obstacle
---> if obstacle.ChangeToWalkLeft = true ; enemy.WalkingRight = false
---> if obstacle.ChangeToWalkLeft = false ; enemy.WalkingRight = true

I hope my text version of the events you need makes sense...

Have a look through the FAQ as I said at the start, there are some great examples of how to do all sorts of things with C2. Enough to take up your whole weekend... Colludium2014-02-01 18:25:30
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,414
Reputation: 57,665

### » Sat Feb 01, 2014 9:12 pm

Hi!

Sorry I might not have been clear enough. I'm looking for a way to do this for a certain amount of seconds. The enemy thing was just an example. I'm trying to use that as an example of how to make something happen for a limited amount of time.
B
9
S
1
Posts: 97
Reputation: 715

### » Sat Feb 01, 2014 9:37 pm

Aha - in that case, you need the Timer Behavior .
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,414
Reputation: 57,665

### » Sun Feb 02, 2014 9:34 am

Thank you very much, that sounds like what I'm looking for! I will check it out asap.
B
9
S
1
Posts: 97
Reputation: 715