lookAt API question

@yaustar i do have one more question i have seen the documents to the lookAt and i do not understand it as far as i can tell from it i think you are supposed to do this:

this.AI.lookAt('Player');

is that not how it works?

API doc: https://developer.playcanvas.com/en/api/pc.Entity.html#lookAt

What part don’t you understand?

I do not understand the whole thing im not understanding how it works… i did what it showed me to do so i did:

this.Player = this.app.root.findByName('Player')
var player = this.Player;
this.entity.lookAt(player);

You have a lowercase “p” instead of upper case. If fixing the case doesn’t work, then try also putting this.Player in the parenthesis

this.entity.lookAt(Player);

or 

this.entity.lookAt(this.Player);

As a newb I don’t have my head fully around why this is sometimes necessary and sometimes not. I need to dig in more on that topic. But I know to try both ways. :^)

Edit: Oops. I glossed over your statement of var player = this.Player. But either way, take a look at the script I posted and/or the example project I posted and go through things step-by-step.

1 Like

Not one of the examples shown in that doc link does that. Look through the docs and read what the parameters should be.

1 Like

it shows this

var position = otherEntity.getPosition();
this.entity.lookAt(position);

oh so i need to get the position of the entity…

Yup. Kinda makes sense. When you point at something you are actually pointing at its location… right?

yes thats what im trying to do

Got it thanks @wturber && @yaustar

:sweat_smile: Could someone tell me a complete script example? Tnx

There is an example and project in this topic.