// update code called every frame
Player.prototype.update = function(dt) {
if(Player.canPlay == false) return;
// Position
var forwardForce = this.entity.forward.clone();
forwardForce.scale(-0.1);
this.entity.translateLocal(forwardForce);
// Rotation
this.currentRotation.copy(this.entity.getLocalRotation());
if(this.dx < 0 && this.currentRotation.y <= 0.3)
this.entity.rotateLocal(0, this.rotationSpeed * dt, 0);
else if(this.dx > 0 && this.currentRotation.y >= -0.3)
this.entity.rotateLocal(0, - this.rotationSpeed * dt, 0);
else
this.entity.rotateLocal(0, 0, 0);
};
Got It ! Leaving it here for others reference.
var position = new pc.Vec3().copy(this.entity.getLocalPosition());
// clamp x position
position.x = pc.math.clamp(position.x, Min, Max);
this.entity.setLocalPosition(position);
3 Likes