Cant get the character to change direction when it hits a wall.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By k4b00m-Hozaifa

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 is_on_wall() 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

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

selamba | 2019-11-28 22:20

Try using a RayCast instead.

Saitodepaula | 2019-12-05 14:08