Random enemy movement

0 favourites
  • 6 posts
From the Asset Store
This template provide Turn Based strategy engine + Rewarded admob + In app purchase + Level unlock + In game store
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

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

    <img src="http://i.imgur.com/ddrNsul.png" border="0" />

    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.

  • 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)

  • 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)

    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.

    <img src="http://i.imgur.com/rZSJQor.png" border="0" />

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)