I think the simple answer is:
func _process(delta: float) -> void:
position.x = direction_offset * enemy.direction
if !has_overlapping_bodies():
enemy.direction *= -1
You can use not
in place of !
if you like.
What are you trying to make this do? I don’t think this is going to do what you want it to; if the thing here doesn’t have an overlapping body it will reverse direction, and then 1/60th of a second later when _process()
gets called again it will do it over again.
Basically, this will be vibrating back and forth at a frequency of half your frame rate. It seems unlikely that’s what you want.
1 Like
Thank you, I will have to dig into this.