i’m new to playcanvas and coding in general and i’m trying to add basic movement but it gives me the error “uncaught typeerrror: cannot read properties of undefined(reading keyboard)” i have looked through the code many times and cannot seem to find the problem
this is the code
var Movement = pc.createScript('movement');
Movement.attributes.add('speed', {type: 'number'});
Movement.attributes.add("jump", {type : "number"});
// initialize code called once per entity
Movement.prototype.initialize = function() {
};
// update code called every frame
Movement.prototype.update = function(dt) {
// calculate force based on pressed keys
if (this.app.keyboard.isPressed(pc.KEY_LEFT)) {
this.entity.rigidbody.applyForce(
-this.speed,
0,
0
);
}
if (this.app.keyboard.isPressed(pc.KEY_RIGHT)) {
this.entity.rigidbody.applyForce(
this.speed,
0,
0
);
}
if (this.app.keyboard.isPressed(pc.KEY_UP)) {
this.entity.rigidbody.applyForce(
0,
0,
this,speed
);
}
if (this.app.keyboard.isPressed(pc.KEY_DOWN)) {
this.entity.rigidbody.applyForce(
0,
0,
-this.speed
);
}
};
if (this.app.keyboard.isPressed(pc.KEY_SPACE)) {
this.entity.rigidbody.applyForce(
0,
this.jump,
0
);
{
}
}