Yes, I’m stuck again.
I’m trying to respawn a player entity, using this:
http://developer.playcanvas.com/en/user-manual/scripting/events/
I have the app.fire(“respawn”) on my code for the death trigger(just a bottomless hole trigger for now).
The player has this in their code, under initialize():
respawn: function () {
console.log("respawn was heard by player object, attempting a respawn.");
this.entity.rigidbody.teleport(this.spawnpoint.getPosition,this.spawnpoint.getRotation);
this.entity.rigidbody.linearVelocity = new pc.Vec3(); //erase any velocity
this.entity.rigidbody.angularVelocity = new pc.Vec3(); //erase any rotational velocity
},
I know the code is firing, because the console will show the “respawn was heard” text. But it instantly crashes out after that when I try to access this.entity. Anything to do with the entity, or anything on the listening object for that matter, will return a null or similar error about the object not existing, and this.spawnpoint also no longer exists if I call console.log(this.spawnpoint) (It was a property setup in the editor on the player object, pointing to the entity for a spawn point).
Is this another problem of scope? How am I supposed to be using these to manipulate anything?
Is the example on the documentation page supposed to be able to do things to the “Display” entity with the x and y values? It doesn’t show a path to actually manipulate the listening object in the example code, so I’m rather lost. The other example of it’s use show to use app. in order to make global messages, but then the object scope is wrong? This is the only other example of fire() being used I found in the docs:
http://developer.playcanvas.com/en/tutorials/beginner/keepyup-part-three/
Surely every object doesn’t need to pass a reference to itself down every single “fire” event call just to enable accessing their data from each other?