How exactly do you make an enemy move towards the player in 3d?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Entity2020 studios

I have been trying to achieve this for ages. I need to know the easiest way to implement it that will actually work. I’ve been stressing myself out trying to make stuff work, but it just doesn’t. What nodes and scripts would I need to do this?

:bust_in_silhouette: Reply From: Rhinoid

If you subtract the position of the enemy from the position of the player you end up with a vector pointing from your player to the enemy.
Now you can just normalize that vector (it makes any vector 1 in length) and then multiply it with the speed you want the enemy to go with (Otherwise all enemies would move with speed 1). Final step is to add that vector to the position of the enemy, making it move in the direction of the player with your given speed.

:bust_in_silhouette: Reply From: Entity2020 studios

I’ve been able to create a basic fix for my problem.

So my game level has the player and the enemy. I was able to obtain the location of the player, and then have the enemy’s location determined by the scene the two are in. This makes the enemy behave the same way as Baldi from Baldi’s basics, teleporting to a location instead of moving there bit by bit. The only problem now is that I have to make the enemy look at the player.

You want the look_at() method. It will rotate your object so that it looks at a point you specify (such as another object).

stormreaver | 2023-04-03 01:15