I’m working on a script that should open/close my door in a PlayCanvas project.
When I comment out this part of the code:
// var player = this.app.root.findByName(‘Player’);
// if (player.getPosition().distance(this.entity.getPosition()) < 4) {
this.toggleDoor();
// }
it works. But if I leave it uncommented, it doesn’t work — even when the player is very close to the door.
Why is this happening, and what is the correct way to check the distance between the player and the door?
Editor link: https://playcanvas.com/editor/scene/2322303
Code Editor link: https://playcanvas.com/editor/code/1394660?tabs=255871351,253118097&focused=255871351
P.S: the script name is doorInteractive.js
