Rigidbody jittering when modifying the linearVelocity

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.entity.rigidbody.linearVelocity = this.velocity;
        this.lerpedMouse.lerp(this.lerpedMouse, this.mouseIndicator.getPosition(), 0.1);
        this.entity.lookAt(this.lerpedMouse, this.entity.up);

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()));
        var mousePos = new pc.Vec3();
        mousePos = this.entity.camera.screenToWorld(this.mouseX, this.mouseY, 100);
        if(this.target.script !== undefined){
            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);
            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.

Okay confirmed that it’s not a Physics problem. I changed the Biplane movement logic to instead of use Physics just increment its local position and it’s still jittering.

Current code:

        this.velocity.copy(this.entity.forward).scale(10 * dt).add(this.entity.getPosition());

So I’m almost 100% sure it has to do with the Camera… going to keep thinking of solutions

So I’ve tried to just not depend on deltaTime for the movement and it appears to move without jittering, not using Physics anymore for this tho, so I’ll have to figure out my own collisions.

Haha, this ended up being like a tiny devlog. Sorry for that! You can delete the thread if you want.

Oh it’s helping me out, because i also think there is something with the Cam. I’ve also strange behaviors registered in two different projects. Could it be that the camera collides with something?! Did your setting hat a mesh with collision at the beginning, a camera which has also a colliding function and a player, which of course also had a collision?! Or did you use the distance to have a range to your “player”?!

This was because I was doing the camera logic on update instead of postUpdate!

1 Like