Godot Version
4.4.1
Hello, I encountered a weird problem when trying to target enemies.
Player’s direction starts glitching when targeting an enemy
Here is the code I use on the Player code:
func _physics_process(delta):
super._physics_process(delta)
move_speed = 0.25
if moving == false:
animation_tree["parameters/conditions/idle"] = true
animation_tree["parameters/conditions/is_moving"] = false
if attacking == true:
animation_tree["parameters/conditions/attacking"] = true
animation_tree["parameters/attack/blend_position"] = direction
else:
animation_tree["parameters/conditions/attacking"] = false
else:
animation_tree["parameters/conditions/idle"] = false
animation_tree["parameters/conditions/is_moving"] = true
animation_tree["parameters/idle/blend_position"] = direction
animation_tree["parameters/walk/blend_position"] = direction
if attacking == true:
animation_tree["parameters/conditions/attacking"] = true
animation_tree["parameters/attack/blend_position"] = direction
else:
animation_tree["parameters/conditions/attacking"] = false
Another minor problem would be that when I tap on another enemy the targeting enemy sprite doesn’t get removed from the previous enemy and I don’t really know how to do that.
func _on_enemy_body_input_event(_viewport: Viewport, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
player.attacking = !player.attacking
if player.attacking == true:
player.id_path = map.find_path(player.global_position, enemy_location) #This is how I set path to the enemy
target_enemy = load("res://Target_enemy.tscn").instantiate()
add_child(target_enemy)
else:
remove_child(target_enemy)