Saturday, July 9, 2022
HomeGame Development3d - Including Z rotation to XY rotation with out polluting the...

3d – Including Z rotation to XY rotation with out polluting the end result


For context, I am making an attempt to make a third particular person area recreation. The spaceship orientation is set by the digicam orientation. I additionally need to have the ability to management the roll of the ship(in my case, that’s the rotation across the Z axis). For instance, when panning the digicam proper I would like the spaceship to have the ability to tilt a bit proper as effectively, when banking the digicam, I would like the spaceship to additionally financial institution accordingly.

I’m able to make the ship level at wherever the digicam is pointing, nevertheless I’m having hassle in relation to controlling the roll of the spaceship. Here’s what I do to level the ship to the digicam goal (tried to make this as generic as potential, since I believe my situation is a theoretical one):

    Vector3 rotationVector = shipZAxisNorm.Cross(cameraTargetNorm);
    Vector3 rotationAxis = rotationVector.GetNormalized();
    float rotationVectorMag = rotationVector.Magnitude();
    float rotationAngle = ATan2(rotationVectorMag,cameraTargetNorm.Dot(shipZAxisNorm);

    float angularSpeed = PI/3;
    float maxAngularSpeed = rotationAngle / delta;
    float minAngularSpeed = (rotationAngle - PI) / delta;
    angularSpeed = Clamp(angularSpeed, minAngularSpeed, maxAngularSpeed);

    Vector3 rotationVelocity = rotationAxis * angularSpeed; // This velocity is then used to spin the ship

Now, the above code makes the ship level in direction of the place the digicam is pointing which is nice. Nonetheless it has a little bit of a tilt. additionally, after I spin the digicam, the ship will inadvertently catch some z rotation as effectively. I would like to have the ability to absolutely management this Z rotation. How would I be capable of add the needed Z rotation to the rotation velocity? Is that this even potential, or do I have to rethink my method?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments