lookAt API question


#1

@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?


Round floating point to integer
#2

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

What part don’t you understand?


#3

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);

#4

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.


#5

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


#6

it shows this

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

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


#7

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


#8

yes thats what im trying to do


#9

Got it thanks @wturber && @yaustar


#10

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


#11

There is an example and project in this topic.