Found a bug in the first person movement script

https://developer.playcanvas.com/en/tutorials/first-person-movement/

Near the end of the code, when the force is finally applied to the player, it curently looks like this:

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

What most devs, when play testing, experience is that when you don’t input with the mouse first, you can’t use the keys and the player won’t move.

To fix this issue, you would just need to replace the && with a ||, so it would look like this:

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

Please fix this in your tutorial page. :blush:

3 Likes

Good catch

1 Like
1 Like