[Solved] FPS character direction

Hi,

I am evaluating playcanvas and so far I like it. I am using the tutorials to learn and right now I’m playing with the FPS Character Controller. I have one question though - what is the easiest way to have the actual character (Geometry entity) facing the same direction as the camera? My character is not round as in the tutorial, and I need to have it heading the right direction at all times.

Thanks,
D.

I would take the camera’s ‘look at’ vector (cameraEntity.forward), project it onto the XZ (floor) plane and do a Math.atan2 calculation on the x and z components of the projected vector to figure out the camera’s angular rotation around the world Y axis. Then, just called playerGeometryEntity.setEulerAngles(0, yRot, 0);

Hi,

Thanks for your input. What I did was to move the FPS from Camera to Character and change the code to the following:

    initialize: function () {
        this.camera = app.root.findByName('Camera');
    },
    update: function (dt) {
        this.entity.setEulerAngles(0, this.ey, 0);
        this.camera.setEulerAngles(this.ex, this.ey, 0);
    },

So far it seems to work…

Thanks,
D.

Nice and simple solution! :smile: