Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Jorge |
I am using Godot 3.2 for a 2D project, and running a script for an enemy to change the direction (flip_h) when is colliding with the walls, however, when the enemy collides with the wall or another enemy the enemy change also the direction.
The code I am using is working only when collides for the first time (ONCE), after that isn’t flipping the direction any more, any ideas?
thanks
extends "res://Actors/Actors.gd"
func _ready() -> void:
set_physics_process(false)
_velocity.x = -speed.x
$enemy1.flip_h = true
func _physics_process(delta) -> void:
_velocity.y += gravity * delta
$enemy1.play("walk")
if is_on_wall():
_velocity.x *= -1.0
$enemy1.flip_h = false
_velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y