[SOLVED] I need help with GetPosition

The error console says getPosition is not a function. Here is my code:

var MonsterLookAt = pc.createScript('monsterLookAt');

// initialize code called once per entity
MonsterLookAt.prototype.initialize = function() {
    this.target = this.app.root.findByName("Plr");

};

// update code called every frame
MonsterLookAt.prototype.update = function(dt) {
    this.entity.lookAt(this.target.getPosition());

};

// swap method called for script hot-reloading
// inherit your script state here
// MonsterLookAt.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/

Hi @SoySauceStudios and welcome!

Your code seems correct to me. I think this.target is undefined. Are you sure there is an entity with the name Plr in your scene?

Oh wait my bad!! Sorry I figured it out. It was something with the entity order. Thank you so much for replying!! :sweat_smile:

1 Like