Need help with enemy movement

Hi everyone! I’m hoping to create an element to where when my main character is within a certain proximity of an enemy, the enemy will emit a weapon. However, I haven’t figured out how to do that with the “proximity” tool- only with “collision,” and I don’t want it to emit only when they collide. I haven’t been able to find a tutorial on it. Does anyone have an idea on how to do this Thanks!


first of all welcome @Tazarooni! do you mind posting the game link?

1 Like

Hi @Tazarooni! Welcome to flowlab. Here’s a simple tutorial I made a while back.

If I were you, I’d use a raycast from the enemy and have [hit] — emit

(make sure the object you want to emit isn’t effected by gravity and is movable, for better gameplay turn off “solid” and turn on collisions and set collision type to polygon) :slight_smile:

Thank you so much for your help! That solved it! At first I had an error still because I didn’t set the raycast to BOTH hit and miss to trigger the emit, but it’s working now. Do you know how to make it raycast independently of a time variable? Right now in order to make it work I have to loop Always --> Timer --> Raycast --> Emit

1 Like

Like, I still would like it if I could have it raycast when the main character comes within proximity of it, not a constant loop or every several seconds :slight_smile:

Like a [once] — [start {timer} ] — [out] — [emit] ?

Go into the timer and turn on repeating? Or shorten the time or raise the time. I don’t really understand what you’re saying, it might just be because I’m tired.

You could have a proximity check always checkd and then if it gets close enough, it triggers the raycast
Always —> Proximity ----> raycast

Oh, that’s what he or she meant…

If that’s the case (and you want a timer) use what MelloJello said but make the timer start at the output of the proximity and the output of the timer goes to the cast on the ray cast.

1 Like

I don’t exactly get why you need to use a raycast to help emit the enemy attack but okay :upside_down_face:

More precise proximity I guess. Maybe he or she or other wants it to only trigger from below or above? I don’t know but I do know that ray casts are super helpful for top-down games.

1 Like

Yes, I think this is what I’m trying to do! I’d prefer to have it triggered by proximity rather than a length of time (for example, I don’t want it firing every 10 seconds if the character isn’t close by, I’d rather have it trigger when the character is in a specific range). Can you walk me through where to drag the arrows for this? I think this is the part I can’t get right.
Would I put the Always out into distance or check of proximity? And where do I drag the x/y to of the Proximity angle/length/cast options? I’ve been trying various combinations but can’t seem to solve it. Thank you for helping! I’m brand new to this.

It’s all good! The only reason I have a timer right now is because it’s the only way I could get it to trigger. When I try and insert proximity at all as the trigger instead of time, I can’t get it to work. I know I’m doing something wrong, but can’t seem to solve it.