Rotate an entity along an axis/direction

How can an entity be rotated along an axis/direction?

It can be any normalized direction, such as Vec3(0.65, 0.25, 0.1).

In general, we need a method like in Unity3D - Quaternion.AngleAxis(float angle, Vector3 axis):

P.S. How to add PlayCanvas suggestions to GitHub?

this should work

It doesn’t work in this case.

Rotation is expected along the ‘forward’ (blue) axis of the entity.

But something completely unexpected happens.

Here is a test project PlayCanvas | HTML5 Game Engine

Had a look, getAxisAngle gives you a rotation for that axis but it needs to be applied to the current rotation of the entity to be applied correctly. I’m not sure if the Unity version requires this or instead sets the rotation the game object to be facing down the axis.

QuaternionAngleAxis.prototype.update = function (dt) {
    if (this.updateRotation) {
        this.angle += dt * 30;
        this.angle %= 360;

        const axis = this.entity.forward;

        const rotation = new pc.Quat();

        rotation.setFromAxisAngle(axis.clone().mulScalar(-1), this.angle);

        const currentRotation = this.entity.getRotation().clone();