I have a game that I am making, and after creating a script to turn on and off the thrusters, I got this " Cannot read properties of null (reading ‘parentElement’) ".
Does anyone know the problem? here is my game: PlayCanvas | HTML5 Game Engine
@Kyle_3_1415 I have had a look to your code and have seen some inconsistent things. Here are the changes I propose.
var Shift = pc.createScript('shift');
Shift.prototype.initialize = function() {
};
Shift.prototype.update = function(dt) {
var app = this.app;
//This is for turning on the extra fire when pressed
if (app.keyboard.isPressed(pc.KEY_SPACE)) {
this.entity.findByName('fire').enabled = true;
console.log("fire");
} else {
this.entity.findByName('fire').enabled = false;
}
};
I am not sure why you had the app.Start() in the code but it was removed. Also, have a look to your models and you will see that there are two ‘fire’ particle systems. The keydown and keyup are events and have to have the appropriate setup. Please have a look to this section of the API documentation to see how these work.
https://developer.playcanvas.com/api/pc.Keyboard.html
1 Like
Ok, it works better now. Thanks!