Calculate the rotation/orientation between two entities

Hi, I’m trying to make an entity chase the player, calculating the movement was pretty easy but my less than mediocre math skills are a bit of an obstacle for the rotation.

In my script I’m using the teleport method of the ridgidbody in the update function, simply because the third person controller tutorial showed it like that. Maybe theres another or a better way but currently this is the core of my chase script:

this.entity.rigidbody.type = pc.BODYTYPE_KINEMATIC;
    this.entity.rigidbody.type = pc.BODYTYPE_DYNAMIC;

    let direction =;

    var pos = new pc.Vec3(direction.x * dt, 0, direction.z * dt);


the first three lines are quite a crutch that I hope to replace now - while this seems to work in orienting the enemy towards the player, switching the rigidbody type each frame is surely less than ideal.

Could anybody point me in a direction or maybe explain how I can calculate the orientation I can pass as a second parameter for the teleport function? As I know both Vec3s I was thinking maybe its something like Math.acos or atan or so but so far google didn’t really show me anything that really made sense to me :smile: wish I had paid more attention back in trigonometry classes but back then I saw next to no usecase for this :sweat: :smile:

Hi @Dinkelborg and welcome back!

In the project below a workaround is used to use lookAt with physics. Maybe this project can help you.