[https://playcanv.as/p/KMNqaQyd/]
I made an car with physics and move it with arrow keys,
up-forward, down-backwards,
Left rotatate to the left, Right rotate to the right
I managed it that the car is moving in the direction of his rotation but there is a mistake at some angles.
var winkelRad = this.entity.getLocalEulerAngles().y * pc.math.DEG_TO_RAD;
var alphaSin = Math.sin(winkelRad);
var alphaCos = Math.cos( winkelRad);
this.xSpeed = alphaSin * this.speed;
this.zSpeed = alphaCos * this.speed;
if(this.app.keyboard.isPressed(pc.KEY_UP)){
this.entity.rigidbody.applyImpulse(this.xSpeed, 0, this.zSpeed);
}
if(this.app.keyboard.isPressed(pc.KEY_DOWN)){
this.entity.rigidbody.applyImpulse(-this.xSpeed, 0, -this.zSpeed);
}
if(this.app.keyboard.isPressed(pc.KEY_RIGHT)){
//this.entity.rotateLocal(0,1, 0);
this.entity.rigidbody.applyTorque(0,5, 0);
}
if(this.app.keyboard.isPressed(pc.KEY_LEFT)){
this.entity.rigidbody.applyTorque(0, -5, 0);
}