Enemies horizontal and vertical random movement

Get help using Construct 2

Post » Wed Sep 03, 2014 4:08 am

Hi,

I have been having problems trying to figure out how to make my enemies move randomly in all four directions (up, down, right, left).

All of my enemies are the same sprite, but I want them all to move on different directions randomly.

Thanks a lot guys!
B
5
S
1
Posts: 38
Reputation: 482

Post » Wed Sep 03, 2014 4:17 am

Hey jminfantem!

What movement behavior are you using on your enemies?
B
33
S
10
G
4
Posts: 48
Reputation: 3,491

Post » Wed Sep 03, 2014 4:22 am

@broknecho I am using the 8 direction behavior.
B
5
S
1
Posts: 38
Reputation: 482

Post » Wed Sep 03, 2014 4:32 am

One way you could try is to:
for each enemy:
1- Set a local variable direction to a random number from 1-4 to pick a direction
2- Compare that variable to pick the direction for each enemy.

Depends if you want the enemy to just turn 90 degrees or possibly turn right around for a 180.

I'll make a sample capx to illustrate.
B
33
S
10
G
4
Posts: 48
Reputation: 3,491

Post » Wed Sep 03, 2014 4:47 am

B
33
S
10
G
4
Posts: 48
Reputation: 3,491

Post » Wed Sep 03, 2014 5:13 am

[Condition: Pick random instance] every x second will be straight forward enough for you to achieve what you want and set random direction.
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Tue Sep 09, 2014 2:44 am

@broknecho this is exactly what I am looking for. The only problem is that there seems to be a bug that replicates the sprite that is moving.

Do you know why?
B
5
S
1
Posts: 38
Reputation: 482

Post » Tue Sep 09, 2014 3:29 am

I was working on it. But I still don't get why the sprite replicates itself.

Also I would like that for every red box(enemy), I have one skeleton...

any ideas on how I might work this out?

@brocknecho
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 38
Reputation: 482

Post » Tue Sep 09, 2014 5:35 am

You should use a single sprite not 4. Create different animation set for a singular sprite, then change the animation as per condition.
B
28
S
8
G
4
Posts: 553
Reputation: 4,914

Post » Tue Sep 09, 2014 5:50 am

I agree to use one sprite, but the capx attached should help work out what you're doing wrong.

Edit:
The sprite wasn't replicating itself. You can check this by running in debug mode and seeing the instance count.
To have an instance of a sprite always associated with another sprite, use a Container (like I did in the capx)
You weren't setting the position of the skeleton sprite to the enemy sprite every tick, so they were not together (I could see that by turning the Enemy sprites Visible).
You don't need to do certain things every tick, like Start ignoring 8Direction input.
You needed 1 direction variable (i.e. instance variable) per sprite. However I changed it to just check the Enemy sprite's angle instead.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Next

Return to How do I....?

Who is online

Users browsing this forum: DarkRoomGames, mekonbekon, yippiez and 11 guests