Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question When rotating a 3D airplane left or right on the X-Z plane, I want to tilt it around the Z axis. he

Discussion in 'Scripting' started by WENKO, May 25, 2024.

  1. WENKO

    WENKO

    Joined:
    Apr 27, 2019
    Posts:
    53
    Code (CSharp):
    1. inputX;  //left and right input values
    2.  
    3.  
    4. // Rotate left/right based on the y-axis
    5. transform.Rotate(0, -inputX * angularSpeed * Time.deltaTime, 0);
    6.  
    7.  
    8. // Tilt left and right based on the z-axis, which is the forward direction on the x-z axis
    9. transform.rotation = Quaternion.Euler(0, 0, -inputX * rotationAngle );
    10.  
    11.  


    ... I entered these two things in a row, but they don't work at the same time; only one of them works;;



    If you go left, lean left

    If it goes to the right, please help me tilt it to the right.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,450