0 votes

Hey, Guys. I am trying to code the enemy script in which for now I am trying to code a feature where the enemy goes in one direction and as soon as it detects a wall it turns around and goes the way. I have coded this according to my knowledge so far in game dev. But every time I run the TestLevel.tscn level the enemy come does from the air and then just flick left and right in its place when I checked the isonwall() function kept switching between true and false even tough there is on wall around it. and when there Is a wall it still keeps going back and forth in a very small space rather than traveling in the other distance. You can check all the scripts and the game files here on my GitHub - https://github.com/k4b00m-Hozaifa/First-Game/tree/master/src

in Engine by (17 points)
edited by

The assumption you made in the title is probably incorrect: isonwall() probably stays true all the time. In this case it will still flip the direction every frame. You can use print(isonwall()) to see its value in real time.

Try using a RayCast instead.

Please log in or register to answer this question.

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.