How do I make a random direction flying enemy ?

0 favourites
  • 9 posts
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • Heya,

    I want to make my enemy acting like this :

    Fly for 1 second in random 360 direction

    Stop for 1 second

    Repeat

    I've tried absolutely everything with the bullet behavior but the enemy stays at 400 speed, or get stucked at 0...

    Any leads ?

  • skdf

    Hi,

    Are you sure you are setting the bullet speed, and not the animation speed for your sprite?

  • skdf

    It is also important to note if you are using a "Every x seconds" condition, the event won't be triggered until x seconds have passed. If the bullet speed is set at 400 by default and your sprite flies off the layout before the x seconds have passed and subsequent actions are implemented, it might seem like its not working. Try adjusting the default speed in the properties window to the left to the desired speed, or to 0.

    That done, if it still does not work:

    Every 2.0 seconds=>

    (sub-event)For Each Enemy=> set bullet speed to ...(40?), set bullet angle of motion to random(360), Wait 1.0 sec, set bullet speed to 0

    That should do it!

  • Oh my god it's working. You're my savior ! I've been on this since 6 hours ago. The solution was the "for each" as a sub-event. And the fact that you've done this in one event. At one point, I think it was doing a weird loop like "When bullet=0 Set to 400, When bullet=400 Set to 0".

    Anyway, thank you very much While we're at it, any idea of how could I tell the enemy to stop moving if it's crashing into a wall ? Actually, it's sliding along it. I've tried "If position X = 50 or less, Set bullet speed to 0" but it doesn't seem very effective. Actually the enemy is bound to layout, maybe I should try to remove it and mess with the position ?

  • skdf

    Do you want the Enemy to stop forever, or just pause, and get back to moving? Do you want it keep going but to bounce off at an angle like a billards ball?

    (In my examples I have a TiledBackground called Wall)

    Stop forever:

    Enemy: On collision with Wall=> Enemy: Set bullet disabled

    Stop and pause:

    Enemy: On collision with Wall=> Enemy: Set bullet speed to 0

    Bounce off:

    No events needed, just make sure the Wall has Solid behavior and the Enemy has its Bullet behavior setting to Bounce of solids set to yes.

    Hope this helps, if not, give me more details on what you want to accomplish!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry I'm not clear, it's 5 A.M where I'm living

    Yeah the "bounce off" seems the most appropriate way ! But your solution is hardened by the setting of my layout :

    There's a spawn outside the visible layout. Every X seconds, an enemy pops and runs into the layout. So with the bounce off, I can't make enemies entering if the walls are solids.

  • skdf on that last note... you could disable collisions until they are inside the layout area.

  • Ragevortex

    Well, it was so easy that I didn't even think of that. Guess my brain is really melted after staying that long on the same problem. Thanks a lot, I'll do thorough tests tomorrow but I think everything should be working now

  • skdf Happens to me all the time. I have a space shooter template that I much later expanded to a game in which one of my main ships has to bounce all over the place... had to do the "hidden wall" solution for that ship only while keeping all the other ships wall free... it was hell. (haven't finished the actual game I'm re-strategizing it to include cinematics and dialogue and revamping the art so I have lots of work to go trough on it.) I wish you the best of luck on your project.

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