3D character model movement

I have a character model whose movement is controlled through WASD. I have also added a walking animation FBX. But when I press any movement key the model just sticks to the ground whilst animating and moving in that particular direction. The orientation is getting glitchy.

It seems to have been caused by this Quaternion modifying block of code, which I’ve used to turn the character in the direction of the pressed key (wasd).

 let angleYCameraDirection = Math.atan2(
                    this.camera.position.x - this.model.position.x,
                    this.camera.position.z - this.model.position.z
                );
                // diagonal movement angle offset
                let directionOffset = this.directionOffset(keysPressed);
                this.rotationQuaternion.setFromAxisAngle(
                    this.rotateAngle,
                    angleYCameraDirection + directionOffset
                );
                this.model.quaternion.slerp(this.rotationQuaternion, 0.1);
                this.model.updateMatrixWorld();

How can I fix this?

@kreysix

Quaternions are used to rotate, not to move through space. So, if you only change quaternion your model will turn towards some direction, but will not move forward. Do you also change your model position value?

– Pavel

Yes @PavelBoytchev . Just basic translateZ() to move the model forward/backward

Also my animations are coming from a mixamo fbx model, and the model is from ReadyPlayerMe.

@kreysix

Most likely I have misunderstood you. I though your problem is that the model is not moving forward.

– Pavel