Weird bug with movement and camera


#1

Here is my project
https://playcanvas.com/project/625746/overview/movement-testing
When standing still you can look around but you can not control the camera whilst trying to move. Also for some reason you cannot move with only 1 key, you need to press two keys e.g. W+D or S+A, i do not know why you can not control the camera whilst moving and why you need to press two keys when. Can someone help point me in the right direction please, where have i gone wrong? Thanks


#2

Re: Two keys for movement bug:

    if (x !== 0 && z !== 0) {
        force.set(x, 0, z).normalize().scale(this.power);
        this.entity.rigidbody.applyForce(force);
    }

For this if statement to be true, both x and z need to be non zero values. When you only press W and you are looking down the world Z axis, only z is non-zero.

You probably wanted || instead of &&.


#3

Thanks for helping with that bug, also do you know why i can move the camera around but once i start to press the WASD keys the camera’s angles are reset to the default angle. Maybe when im rotating the camera i should be rotating the entity aswell?