Hi there, today I began developing a multiplayer aircraft shooter, inspired by War Thunder.
In the game you control a biplane in third person with your Mouse.
The problem is I have seen that the biplane jitters a lot when adding velocity. It really doesn’t matter if I use the linearVelocity (I’m aiming on that), or I apply a force.
Not really sure what’s going on but I can’t figure it out so I am looking for perspective from other devs.
I am also setting the Camera position & rotation to chase the biplane, I’ve tried to see if instead of a Physics jittering problem it was the Camera, but it doesn’t appear to.
This is the code that moves the biplane based on its forward vector & rotates it to face the current mouse position on screen
this.velocity.copy(this.entity.forward).scale(this.throttle);
this.entity.rigidbody.linearVelocity = this.velocity;
this.lerpedMouse.lerp(this.lerpedMouse, this.mouseIndicator.getPosition(), 0.1);
this.entity.lookAt(this.lerpedMouse, this.entity.up);
this.entity.rigidbody.syncEntityToBody();
This is the code that makes the Camera chase the Biplane
// set the camera position behind the biplane, and a little higher into perspective
this.pos.copy(this.target.forward).scale(-3).add(new pc.Vec3().copy(this.entity.up).scale(1).add(this.target.getPosition()));
this.entity.setPosition(this.pos);
var mousePos = new pc.Vec3();
mousePos = this.entity.camera.screenToWorld(this.mouseX, this.mouseY, 100);
if(this.target.script !== undefined){
this.target.script.planeController.mouseIndicator.setPosition(mousePos);
this.lastMousePos.lerp(this.lastMousePos, mousePos, 0.1);
// calculate smooth lookat
var lookAtPos = new pc.Vec3();
var calc = new pc.Vec3();
calc.sub2(this.target.getPosition(), this.target.script.planeController.mouseIndicator.getPosition()).scale(0.5);
lookAtPos.copy(this.target.forward).scale(5).add(this.target.getPosition());
this.finalLookAtPos.lerp(this.finalLookAtPos, lookAtPos, 0.5);
this.entity.lookAt(this.finalLookAtPos, this.target.up);
}
I have uploaded the current build of the game to http://skyarena.io - I hope you can test it out and let me know what you think is going on there.