#Enemy doesn't move

40 messages · Page 1 of 1 (latest)

twilit agate
#

For some reason my enemy doesn't move, however it does face towards the player. I used the same script as a youtuber, and no one else seemed to have issues:

extends CharacterBody3D

const SPEED = 3.0
@export var player : Node3D
@export var turn_speed = 4.0

func _physics_process(delta):
    if player != null:
        $FaceDirection.look_at(player.global_transform.origin, Vector3.UP)
        rotate_y(deg_to_rad($FaceDirection.rotation.y * turn_speed))
        $NavigationAgent3D.set_target_position(player.global_transform.origin)
        velocity = ($NavigationAgent3D.get_next_path_position() - transform.origin).normalized() * SPEED * delta
        move_and_collide(velocity)

I tried getting rid of the protonscatter node, in case that was interfering with it, it was not. I tried moving the raptor up, in case it was colliding with the ground, and again, it was not. I'm honestly at a loss...

(also lmk if I forgot to include any important bits you'd need to see)

twilit agate
#

ok so 1 of my mistakes was not putting the raptor as a child of the navigationregion. however now it still only moves in a single line

#

(not towards the player)

glacial imp
#

$NavigationAgent3D.set_target_position(player.global_transform.origin)

#

oh sorry, no, that's correct afaik

#

velocity = ($NavigationAgent3D.get_next_path_position() - transform.origin).normalized() * SPEED * delta
is what I meant to post -- that's not our global transform.origin

#

so the velocity you calculate is off

twilit agate
#

oh that makes sense, I'll try that

#

nope, now it's stuck in place again

#

also this might be a dumb question but should the raptor (with the NavAgent) be childed to the NavRegion?

glacial imp
#

I don't have any familiarity with navagents/regions so I dunno, sorry!

#

(I would've guessed not, but I dunno!)

#

nope, now it's stuck in place again
what's the code look like?

twilit agate
#

const SPEED = 3.0
@export var player : Node3D
@export var turn_speed = 4.0

func _physics_process(delta):
    if player != null:
        $FaceDirection.look_at(player.global_transform.origin, Vector3.UP)
        rotate_y(deg_to_rad($FaceDirection.rotation.y * turn_speed))
        $NavigationAgent3D.set_target_position(player.global_transform.origin)
        print("player: ", player.global_transform.origin)
        print("nav: ", $NavigationAgent3D.get_next_path_position())
        velocity = ($NavigationAgent3D.get_next_path_position() - global_transform.origin).normalized() * SPEED * delta
        move_and_collide(velocity)
twilit agate
#

I could send you the project if that would help

glacial imp
#

no thank you 🙂

#

I think that looks right but it's odd to set velocity to include delta

#

(but move_and_collide wants a veloc with delta in it, so I bet the code is correct from that POV. But maybe move the *delta into just the move_and_collide expression, since that is more correct. But I still don't know why it's broken 😄 )

hallow burrow
#

delta is fine

#

crank the speed up to 100. sometimes things are moving, but so slow you can't tell

#

can you set the navigation region to use both meshes and collisions

#

I am not convinced that you have a valid bake

hallow burrow
#

your ground should have a light blue fractal pattern like this if the nav mesh is baking @twilit agate

twilit agate
#

this is what mine looks like

twilit agate
hallow burrow
#

try changing the geometry -> parsed geo type to both

#

right now it only uses meshes and if you dont have the floor mesh as a child of the nav region it can't use it

twilit agate
twilit agate
#

could it be that the region is too big or something?

#

it's 2048x2048 right now heh

hallow burrow
#

lord have mercy

#

thats meters not pixels

#

make it the default for now

twilit agate
#

this was in fact the issue

#

I may be stupid on a whole other level

hallow burrow
#

as long as you solved it you remain smart!