I have this code for Godot 4. The problem is that when the enemies collide with each other, I want them to surround the player, but instead, the enemies bunch up in a horizontal line, which is not what I want. Here’s my code:
extends CharacterBody2D
var health = 100
var blood = preload("res://scenes/blood.tscn")
var move_speed = 150
@onready var player : CharacterBody2D = get_tree().get_first_node_in_group("player")
func _ready():
$Enemie1.play("idle")
func _physics_process(delta):
var dir_to_player = global_position.direction_to(player.global_position)
velocity = dir_to_player * move_speed
move_and_slide()
func take_damage():
health = health - Global.daño
$Enemie1.play("damage")
await get_tree().create_timer(0.1).timeout
$Enemie1.play("idle")
if health <= 0:
print(self.position)
bloodInstance()
queue_free()
func bloodInstance():
var blood_instance = blood.instantiate()
blood_instance.position = self.position
get_tree().root.add_child(blood_instance)
@onready var nav = $your_navigation_agent
var direction = Vector2()
func _physics_process(_delta):
direction = nav.get_next_path_position() - global_position
direction = direction.normalized()
var intended_velocity = direction * move_speed
nav.set_velocity(intended_velocity)
ty for reply ^^ I tried but the problem persists, I tried adding a collision repellent and it works (sort of) but I think it’s finally resolved for the moment ahahah