Euler angles when applying AddForceAtPosition?

This is my controller code:

    void Update()
    {
        if (Input.GetKey(KeyCode.Keypad7))
        {
            ColdGasThrusterServices[0].Left();
            ColdGasThrusterServices[2].Left();
        }
        if (Input.GetKey(KeyCode.Keypad9))
        {
            ColdGasThrusterServices[0].Right();
            ColdGasThrusterServices[2].Right();
        }
        if (Input.GetKey(KeyCode.Keypad8))
        {
            ColdGasThrusterServices[0].Down();
            ColdGasThrusterServices[2].Up();
        }
        if (Input.GetKey(KeyCode.Keypad2))
        {
            ColdGasThrusterServices[0].Up();
            ColdGasThrusterServices[2].Down();
        }
    }

And this is my individual thruster service (has 4 thrusters):

    public void Right()
    {
        ThrusterRight.Play();
        RocketRigidBody.AddForceAtPosition(-ThrusterRight.transform.forward, ThrusterRight.transform.position);
    }

    public void Left()
    {
        ThrusterLeft.Play();
        RocketRigidBody.AddForceAtPosition(-ThrusterLeft.transform.forward, ThrusterLeft.transform.position);
    }

    public void Up()
    {
        ThrusterUp.Play();
        RocketRigidBody.AddForceAtPosition(-ThrusterUp.transform.forward, ThrusterUp.transform.position);
    }

    public void Down()
    {
        ThrusterDown.Play();
        RocketRigidBody.AddForceAtPosition(-ThrusterDown.transform.forward, ThrusterDown.transform.position);
    }

When i roll my rocket (apparently everything is OK!):
4467835--410350--2019-04-25_00-52-13.gif
When i pitch my rocket (nothing wrong so far):
4467835--410353--2019-04-25_00-54-40.gif
Now, look what happens when I try to do Pitch and then Roll:
4467835--410356--2019-04-25_00-57-55.gif

It’s been many hours that I try to understand what is happening! Can someone help me?

Looks correct to me. When an object gains enough angular velocity around an axis, is quite difficult to make that object rotate around a different axis. Think on a kind of gyroscopic effect.

1 Like

In this simulation things happen differently.

For example on Pitch + Roll:
4468927--410521--2019-04-25_07-48-35.gif

I just forgot to ask, what exactly seems right to you? My implementation or Unity physics?

I tested it with AddRelativeTorque but the problem persists.

    void RollPlus()
    {
        RocketRigidbody.AddRelativeTorque(Vector3.down);
    }

    void RollMinus()
    {
        RocketRigidbody.AddRelativeTorque(Vector3.up);
    }

    void PitchPlus()
    {
        RocketRigidbody.AddRelativeTorque(Vector3.right);
    }

    void PitchMinus()
    {
        RocketRigidbody.AddRelativeTorque(Vector3.left);
    }

Both. You’re applying correct forces, and you’re getting the correct effect of those forces.

That’s not a simulation, but a demonstration of the coordinate system. Specifying the rotation rates around specific axes is different than simulating the rotational effects of forces applied to a rigidbody in certain positions and directions.

This is actually a simulation. Summing two rotations (first around Y, second around Z) has the exact same effect you’re observing in your case:

https://www.youtube.com/watch?v=rEhNgR17JEI

The problem you’re facing is understanding the rotations not as a “compound” of individual rotations, but as an angular momentum as a whole. When you apply a torque (either directly or as a force) you’re adding angular momentum to your rigidbody. Once you stop applying forces/torques the amount of angular momentum remains constant, yet the object may exhibit an apparently chaotic rotation. Typically, the resulting rotation tends to align itself around the axis of smaller inertia.

Understandably, I’ve rarely seen rockets, spacecrafts, satellites, etc executing a rotation around more than an axis a time. They must be very aware of how they are adding or removing angular momentum.

There are other surprising effects of rotations depending on the shape of the body, such as the Dzhanibekov effect:

https://www.youtube.com/watch?v=1x5UiwEEvpQ

2 Likes

Thank you for the explanation!

1 Like