here is my code:
var Playercontroler = pc.createScript('playercontroller');
playercontroller.attrbuttes.add('speed', {
type: 'number',
defualt: 10
});
// initialize code called once per entity
Playercontroller.prototype.initialize = function() {
};
// update code called every frame
Playercontroller.prototype.update = function(dt) {
var rb = this.enitity.rigidbody;
var movehorazontal = 0;
var movevertical = 0;
};
if(this.app.keyboard.isPressed(pc.key_left)) {
movehorazontal = -1;
}
if(this.app.keyboard.isPressed(pc.key_right)){
movehorazontal = 1;
}
if(this.app.keyboard.isPressed(pc.key_up)){
movevertical = -1;
}
if(this.app.keyboard.isPressed(pc.key_down)){
movevertical = 1;}
var moveVect = new pc.vec3(movehorazontal 0, movevertical);
Hi @Team_TEM and welcome! Below my version of your code. In this version I mainly corrected a few typos. I also replaced the last line with a line that actually moves your player. I cannot guarantee that everything will work properly now, you have to check this yourself.
var Playercontroler = pc.createScript('playercontroller');
Playercontroller.attrbuttes.add('speed', {
type: 'number',
default: 10
});
// initialize code called once per entity
Playercontroller.prototype.initialize = function() {
};
// update code called every frame
Playercontroller.prototype.update = function(dt) {
var rb = this.entity.rigidbody;
var moveHorizontal = 0;
var moveVertical = 0;
if (this.app.keyboard.isPressed(pc.key_left)) {
moveHorizontal = -1;
}
if (this.app.keyboard.isPressed(pc.key_right)){
moveHorizontal = 1;
}
if (this.app.keyboard.isPressed(pc.key_up)){
moveVertical = -1;
}
if (this.app.keyboard.isPressed(pc.key_down)){
moveVertical = 1;
}
// move the player
rb.applyForce(moveHorizontal * this.speed, 0, moveVertical * this.speed);
};