[SOLVED] Can't get lookAt to work

I have a entity called Zombie which I need to chase the player, I got the movement to work, Zombie is using RigidBody and after a few searches I found it lookAt wont work on an entity with RigidBody, so I put Zombie’s model inside a parent entity which I made the parent entity have the RigidBody and do the movement, now for some reason, even inside a parent I can’t get lookAt to work on the Zombie model, here’s the code.

var ZombieAi = pc.createScript('zombieAi');

// initialize code called once per entity
ZombieAi.prototype.initialize = function() {
    this.player = this.app.root.findByName('player');
    this.maleArm = this.app.root.findByName('ZombieModel');
    this.speed = 2; // adjust as needed
};

// update code called every frame
ZombieAi.prototype.update = function(dt) {
    var direction = this.player.getPosition().clone().sub(this.entity.getPosition());
    direction.y = 0; // don't move up or down
    direction.normalize();

    var eulerAngleX = this.maleArm.getEulerAngles().x;
    var eulerAngleY = this.maleArm.getEulerAngles().y;
    var eulerAngleZ = this.maleArm.getEulerAngles().z;
    
    this.maleArm.lookAt(this.player.getPosition());
    this.maleArm.setEulerAngles(90,  this.maleArm.getEulerAngles().y, this.maleArm.getEulerAngles().z);
    
    // this.entity.lookAt(this.player.getPosition());

    // move the entity towards the player
    this.entity.rigidbody.applyImpulse(direction.scale(this.speed));
};

This script is attached to the parent which contains the ZombieModel

Hi @Saylent!

I don’t see where you apply the rotation of the model to the parent.

Below an example project that can be useful.

https://playcanvas.com/project/808772/overview/look-at-with-physics

Hello again I got the code working, instead of Euler angles I used Rotation, now the entity is following the player via RigidBody and the 3D model inside the RigidBody is looking at the player, the problem with Euler angles is that it rotates the Zombie entity in a weird way, Rotation fixed the problem for me

var ZombieAi = pc.createScript('zombieAi');

// initialize code called once per entity
ZombieAi.prototype.initialize = function() {
    this.player = this.app.root.findByName('player');//MaleArm
    this.maleArm = this.entity.children[0];
    this.speed = 2; // adjust as needed
    this.health = 100;
};

// update code called every frame
ZombieAi.prototype.update = function(dt) {
    var direction = this.player.getPosition().clone().sub(this.entity.getPosition());
    direction.y = 0; // don't move up or down
    direction.normalize();

    var eulerAngleX = this.maleArm.getRotation().x;
    var eulerAngleY =  this.maleArm.getRotation().y;
    var eulerAngleZ = this.maleArm.getRotation().z;
    
    this.maleArm.lookAt(this.player.getPosition());
    this.maleArm.rotateLocal(90, eulerAngleY - 180, 0);
    
    // this.entity.lookAt(this.player.getPosition());

    // move the entity towards the player
    this.entity.rigidbody.applyImpulse(direction.scale(this.speed));

};