Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. 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,369