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.lookAt(this.target.getPosition()); this.entity.rigidbody.type = pc.BODYTYPE_DYNAMIC; let direction = this.target.getPosition().clone(); direction.sub(this.entity.getPosition().clone()); direction.normalize(); var pos = new pc.Vec3(direction.x * dt, 0, direction.z * dt); pos.normalize().scale(this.walkingSpeed); pos.add(this.entity.getPosition()); this.entity.rigidbody.teleport(pos);
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 wish I had paid more attention back in trigonometry classes but back then I saw next to no usecase for this