How do I make a random direction flying enemy ?

Get help using Construct 2

Post » Sat Jul 23, 2016 12:52 am

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 ?
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Sat Jul 23, 2016 1:09 am

@skdf

Hi,
Are you sure you are setting the bullet speed, and not the animation speed for your sprite?
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Sat Jul 23, 2016 1:23 am

@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!
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Sat Jul 23, 2016 1:53 am

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 ?
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Sat Jul 23, 2016 2:30 am

@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!
B
16
S
9
G
5
Posts: 74
Reputation: 4,120

Post » Sat Jul 23, 2016 3:24 am

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.
Last edited by skdf on Sat Jul 23, 2016 3:34 am, edited 1 time in total.
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Sat Jul 23, 2016 3:31 am

@skdf on that last note... you could disable collisions until they are inside the layout area.
Freefall Bird
B
47
S
9
G
5
Posts: 281
Reputation: 5,803

Post » Sat Jul 23, 2016 3:44 am

@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 :)
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Sat Jul 23, 2016 3:55 am

@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.
Freefall Bird
B
47
S
9
G
5
Posts: 281
Reputation: 5,803


Return to How do I....?

Who is online

Users browsing this forum: Lordshiva1948 and 6 guests