I want a box to point to my player but when I made the code it did not work. Can anybody help?
var EnemyLookAt = pc.createScript('enemyLookAt');
EnemyLookAt.attributes.add('Player', {type : 'entity'});
// initialize code called once per entity
EnemyLookAt.prototype.initialize = function() {
};
// update code called every frame
EnemyLookAt.prototype.update = function(dt) {
this.entity.lookAt(this.Player);
};
Hi @PhilipJeffrey !
For lookAt
you need to use a position, so it should be something like below.
this.entity.lookAt(this.Player.getPosition());
Check also my topic about lookAt
.
Why is the lookAt function always backwards? Is there no way to change this? Only for that I have to use a child entity. Not a problem, but such things make my project a bit messy.
2 Likes
It didn’t seem to work, huh? Do you know why?
Can you tell what happend instead?
Here is the updated code:
var EnemyLookAt = pc.createScript('enemyLookAt');
EnemyLookAt.attributes.add('Player', {type : 'entity'});
// initialize code called once per entity
EnemyLookAt.prototype.initialize = function() {
};
// update code called every frame
EnemyLookAt.prototype.update = function(dt) {
this.entity.lookAt(this.Player.getPosition());
};
It did not point to the player.
It did not point to the player
Sorry, I can’t help you if you don’t provide enough information. I suggest to check the topic I shared in my first reply. Please also note that lookAt
doesn’t work with a dynamic rigidbody.
The box is connected to a model do you think that would be the case?
Can you share an editor link of your project please?
Oh wait I figured it out! Thanks for the help!
Great! Can you share your solution for others?