Hello!
I am attempting to create a flight simulator. Currently, my Airplane can fly around a bit, but I’m looking to make it climb and dive slowly according to the cursor location on the screen.
My hope is to make it move towards that height slowly, to keep it as realistic as possible.
Any help would be deeply appreciated!
Here is my code:
var Test = pc.createScript('test');
// Initialize code called once per entity
// Update code called every frame
Test.prototype.update = function(dt) {
var forwardForce = this.entity.forward.clone();
forwardForce.scale(-10);
var playerPos = this.entity.getPosition();
// Sets the forward force values
if (this.app.keyboard.isPressed(pc.KEY_W)){
forwardForce.scale(5);
}
else{
forwardForce.scale(0);
}
// Sets sideways force values
var sideForce = this.entity.right.clone();
if (this.app.keyboard.isPressed(pc.KEY_A)){
this.entity.rigidbody.applyTorque(this.entity.forward.scale(2));
sideForce.scale(5);
}
else if (this.app.keyboard.isPressed(pc.KEY_D)){
this.entity.rigidbody.applyTorque(this.entity.forward.scale(-2));
sideForce.scale(-5);
}
else{
sideForce.scale(0);
}
// Applies the sideways and forward force values that have been set using the above if statements
this.entity.rigidbody.applyForce(forwardForce);
this.entity.rigidbody.applyForce(sideForce);
};