+1 vote

I have a mob and a player in a 3d scene of a game and till now I am able to move the mob twards the player but unable to rotate it towards the player. please someone help me

Godot version v3.2.3-stable_win64
in Engine by (942 points)

Use the look_at method of your mob node.

1 Answer

0 votes
Best answer

You can use the look_at() function:

look_at ( Vector3 target, Vector3 up )

For example, you could add the following code to your mob script:

func _physics_process(delta):
      look_at(player_reference.global_transform.origin, Vector3.UP)

Of course, this is not a perfect solution since it would also make the mob rotate up and down towards the player, so you might want to set a custom y value in the target Vector.

by (49 points)
selected by

by using $mesh.look_at(player.translation, Vector3.UP) it rotates in the opposite direction of player. Any way to fix it?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.