I tried to get my entity to point to another after hearing an event, but I can not. I think I’ve written everything well, but I just do not get it
var PointAt = pc.createScript('pointAt');
PointAt.attributes.add("targetEntity", {type: "entity", title: "Target Entity"});
PointAt.prototype.initialize = function() {
this.app.on("single", this.onSingle,Event,this);
this.defaultForwardDirection = this.entity.forward.clone();
this.directionToTarget = new pc.Vec3();
};
PointAt.prototype.onSingleEvent = function(dt) {
var targetPosition = this.targetEntity.getPosition();
var pointerPosition = this.entity.getPosition();
var pointerScale = this.entity.getLocalScale();
var distance = pointerPosition.sub(targetPosition).length();
pointerScale.z = distance;
{ this.entity.setLocalScale(pointerScale);
// Always face the target postition
this.entity.lookAt(targetPosition);}