Enemy behavior with instance variables

Get help using Construct 2

Post » Fri Sep 11, 2015 12:42 am

I'm trying to have the enemies in my game jump every X seconds, based on individual value set on each enemy. The enemies use platform behavior (well, PlatformPlus to be exact) and I added an instance variable to the enemy sprite to control the frequency of the jump. ("every ENEMY.frequency seconds" -> "ENEMY simulate PlatformPlus pressing jump")

This works with one enemy, but when there are multiple enemies they all jump based on the frequency value on the first enemy, instead of their own. I tried adding "for each" condition but that only resulted in the first enemy jumping and the other enemy standing completely still. I've probably overlooked something here as there must be a simple solution to this, any help would be greatly appreciated!

Also, I would like to have another instance value for the enemies for delay/offset seconds (so if for example two enemies have their jumping frequency set to 4 seconds, and the other one has delay set to 2 seconds, it will wait 2 seconds before proceeding to jump whereas the first one with delay value of 0 will jump instantly. What would be a good way to implement this kind of behavior? Thanks in advance!
B
32
S
9
G
4
Posts: 131
Reputation: 4,346

Post » Fri Sep 11, 2015 6:20 am

add timer behavior

on enemy create start timer"jump" random(2,4) (once)

for each enemy
ontimer "jump" :simulate jump and start timer "jump" random(2,4) (once)
Image Image
B
22
S
13
G
135
Posts: 871
Reputation: 70,320

Post » Wed Sep 30, 2015 8:16 pm

MadSpy wrote:..


Thanks MadSpy and sorry about the late reply, I've been very busy with work and have not had much time for game dev last couple of weeks, sadly :( Hope to get back to more active development soon! But I just tried and that seems to work and fix the issue I had with the enemies, so thanks a lot!:)
B
32
S
9
G
4
Posts: 131
Reputation: 4,346


Return to How do I....?

Who is online

Users browsing this forum: odiusfly and 28 guests