#how to create multiple enemy objects, each following player?

1 messages · Page 1 of 1 (latest)

quick scroll
#

running into an issue where i have an enemy.tscn

added 2 of these objects to main...in enemy.gd i have NavigationAgent2D...but, n enemies just follow the same target path as the 1st

How do i make this unique? is there simply a godot "make this unique" so i can just place mulitple enemies in the scene, and benefit from the node placement (vs say, dyanmically via instance())

frail vector
#

scene instances are unique, they may share resources (which do literally have a "make this unique" button) but resources are not used for setting targets in navigation agents

#

so, how are you setting the target? maybe it's a code issue

quick scroll
#

okay. enemy.gd's code:

extends CharacterBody2D

const SPEED = 100.0
const JUMP_VELOCITY = -400.0

@onready var navAgent: NavigationAgent2D = get_node("/root/main/enemy/navigationAgent")
@onready var player = get_node("/root/main/player")
func _physics_process(delta: float) -> void:
    updatePath()
    
    # Add the gravity.
    if not is_on_floor():
        velocity += get_gravity() * delta

    var path = navAgent.get_next_path_position()
    var direction = (player.position - navAgent.get_next_path_position()).normalized()
    velocity.x = direction.x * SPEED

    move_and_slide()

func updatePath():
    navAgent.target_position = player.position
    print("resetting target to :" + str(navAgent.target_position))

    ```
#

goal being, they should all independently find their way to the player

#

is it the ref to the navagent that's the issue?

frail vector
#

yes

#

if it's a part of the enemy scene (which it definitely should be) use local paths

quick scroll
#

okay perfect, that works. thanks!