Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Correctly smoothly decrease pitch & roll (but no yaw) angles

Discussion in 'Physics' started by syjgin, Jun 15, 2020.

  1. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    136
    Hello, I'm trying to implement dirijible controlling, and have to smoothly decrease pitch (added by user) and roll (collision result) angles without affecting the yaw component. I moved center of mass to the bottom of rigid body, but that had no effect. So, I have to decrease the pitch angle myself in the FixedUpdate:
    Code (CSharp):
    1. if (!_inputHandler.IsVerticalRotationPressed)
    2.             {
    3.                 if (verticalAngle > Constants.MovementConfig.MinVerticalAngle)
    4.                 {
    5.                     float diff = _rigidBody.rotation.eulerAngles.x < 180 ? 0.1f : -0.1f;
    6.                     _rigidBody.MoveRotation(Quaternion.AngleAxis(diff, transform.localToWorldMatrix.MultiplyVector(Vector3.left)) * _rigidBody.rotation);
    7.                     _targetRotation = _rigidBody.rotation;
    8.                 }
    9.                 else
    10.                 {
    11.                     Quaternion temp = _rigidBody.rotation;
    12.                     Vector3 eulerAngles = temp.eulerAngles;
    13.                     eulerAngles.x = 0;
    14.                     _rigidBody.rotation = Quaternion.Euler(eulerAngles);
    15.                     _targetRotation = _rigidBody.rotation;
    16.                 }
    17.             }
    Maybe, there are some more clean way to do that exists?