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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Rotating on 2 axes Independently at the same time

Discussion in 'Scripting' started by CodeKino, Jul 9, 2015.

  1. CodeKino

    CodeKino

    Joined:
    Jul 9, 2015
    Posts:
    3
    Hi everyone. I am currently trying to code a saw blade where the arrow keys control the rotation of the saw and
    space bar causes the blade to start spinning fast to prepare for sawing. I'm currently having troubles with doing
    both of these things simultaneously without causing a weird diagonal rotation. Does anyone have any tips on
    how to get this working? Below is what I have so far

    Code (CSharp):
    1.     void Update() {
    2.         if (Input.GetKeyDown ("up")) {
    3.             newRotation = Quaternion.Euler (0, 90, 0) * newRotation;
    4.         } else if (Input.GetKey ("space")) {
    5.            rb.AddTorque(transform.up * revSpeed * Time.deltaTime);
    6.         }
    7.  
    8.           transform.rotation = Quaternion.Slerp (transform.rotation, newRotation, Time.deltaTime * switchSpeed);
    9.     }
     
  2. CodeKino

    CodeKino

    Joined:
    Jul 9, 2015
    Posts:
    3