Random enemy movement

Get help using Construct 2

Post » Tue Feb 12, 2013 2:26 am

I'm trying to create some semi-random movement from enemies.

My enemies are have an 8-direction behavior (restricted to just 4 directions and Set Angle to no) and I'm trying to get them to move around fairly randomly.

What I've been doing so far is running an action every 3-7 seconds where it'll change the direction of the sprite.

This was working well previously when I was using a bullet behavior, but the sprite would then end up spinning around - which it shouldn't.

Using the 8-direction behaviour, how would I get my sprite to move up, down, left, or right?

I tried setting a random number every tick between 0 and 3, then choosing a direction based on that number every so often, but the sprite's direction would never change (I was trying to simulate a button press, but I have those disabled since this isn't the player character)

Any thoughts on this would be greatly appreciated.
B
3
Posts: 18
Reputation: 436

Post » Tue Feb 12, 2013 5:09 am

It's hard to understand exactly where you are since you haven't posted a link to your project as a capx, I'm not sure what's going on but I'll try to help.

You *should* be using the "simulate button press" actions in the event editor to control the non-player sprites. The player can't control the sprites if you set the default controls to "no" in the layout. As long as you're using the "simulate button press" actions the sprite should be using the "set angle" movement property you can change in the layout.

I really can't tell you more until you post a capx or at least a screenshot of your entire event sheet. Can you be any more specific about what the problem is?Phyvo2013-02-12 05:10:27
B
6
S
1
Posts: 40
Reputation: 917

Post » Tue Feb 12, 2013 2:48 pm

Here's the event sheet I've got associated with this particular enemy.



Hopefully this will help.

With this, the enemy just keeps walking to the right.

Also, right now there's only one instance of this enemy, so it *should* be 'randomly' selecting only her.scheda2013-02-12 14:49:39
B
3
Posts: 18
Reputation: 436

Post » Tue Feb 12, 2013 3:17 pm

In your every tick event you are setting direction to random, that would cause the spinning. Move that under the random condition. Also take out 'female_zombie_direction' conditions away from under that condition, and move them to the top level. You can remove the every tick condition all together. Might work. :)

EDIT: Also, rather than round/random use choose(0,1,2,3)vee412013-02-12 15:19:01
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Feb 13, 2013 2:59 am

[QUOTE=vee41] In your every tick event you are setting direction to random, that would cause the spinning. Move that under the random condition. Also take out 'female_zombie_direction' conditions away from under that condition, and move them to the top level. You can remove the every tick condition all together. Might work. :)

EDIT: Also, rather than round/random use choose(0,1,2,3)[/QUOTE]

Thanks for the help, Vee.

I've made some changes based on your advice, and it's working great except one particular point. I'm now getting all of the female zombies changing direction together.

I realize it has something to do with picking a random zombie instance, but after about half an hour of toying with different placements, I'm not sure what else to change.

Here's where I'm at right now.

B
3
Posts: 18
Reputation: 436

Post » Wed Feb 13, 2013 6:17 am

Remove all pick random conditions and add For Each zombie - condition after your every x seconds condition.

The idea is that whenever you randomize the direction, you do it for each zombie. The direction conditions just move the zombies with specified directions. :)

Also, instead of global variable (every zombie has the SAME direction) you should use instance variables. Give your zombie object 'Direction' variable and modify your every x seconds condition to set that instead of global variable.vee412013-02-13 06:47:28
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 22 guests