How do I make this 3D Body always face the player?

Godot Version

4.4

Question

How do I make the NPC always face the player?

I want this NPC to always look at the player by rotating on the Y axis but for some reason its not working and when I put _process or _process_physics it just dissapears from existance. Help me

extends StaticBody3D

@onready var player = get_parent().get_node("Player")

func ready(delta):
	look_at(player.position)

You don’t have to use look_at necessarily, you can also set the Billboard mode in the Sprite3Ds properties.

look_at() returns a value; you need to assign that to the object’s rotation.

You’re also calling look_at() in _ready() which happens once when the node enters the scene tree. You need to call that every update.

but how would I make the NPC constantly rotate to the player? Gen question bc I watched 11 tutorials and none worked for me and tbh Im pretty new to coding

As I mentioned before, click on your Sprite3D, scroll down to Flags and set Billboard to Enabled.

image

OOOOH OKKKK It actually worked lmao thankiesss! Didnt know that was an option lol

1 Like

@tibaverus has the simple answer; if you enable billboard it will always face the camera. That’s what billboard does.

In general, though, like for example if you wanted to do this with something that was 3D rather than a sprite, the way you’d do it would be something like:

func _physics_process(delta: float):
    [...stuff...]
    rotation = look_at(player.position)
    [...stuff...]