0 votes

I want to run a function(signal to be more accurate) for as long as my KB2D is in the detection_area

I tried to use while loop but it makes the engine to not respond and crush...
here is what I tried

func onChasingDetectionbodyentered(body):
if body.isingroup("player"):
x = 1
while x == 1:

func onChasingDetectionbodyexited(body):
x = 0
motion.x = 0

note: I used brackets only here to make the question a bit more readable


in Engine by (21 points)

1 Answer

0 votes

while loop will just run until it's broken, which will be never in your case.

have a function that moves to the player. have an if statement in the process function that calls the function to move to the player if a certain variable like "player" is true. When the player enters the detection area set player to true or the player or whatever. When the player leaves the area set player to false or null.

by (6,296 points)

Yeah I tried that but it won't work because the body argument in the func onChasingDetectionbodyentered(body)

if I call this specific func in the process function it will show an error due to there are no arguments

Don't call it in the process function. If you connected the signal correctly it will be called when the signal is emitted.

I simply connectrd the onbodyentered signal...

Okay, and did that fix it?

No bro
I can't figure out a way to do it
the problem is the "body" paramter
if only I could use it outside of the signals

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.