Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

transform.rotation delayed ?

Discussion in 'Scripting' started by bigboybifdick, Jun 24, 2015.

  1. bigboybifdick

    bigboybifdick

    Joined:
    Feb 8, 2014
    Posts:
    60
    Hi,

    I'm wondering, is it possible to delay transform.rotation by any way at all ?
    I know it's pretty easy with transform.rotate
    But as i'm using an angle (right stick of the gamepad) to rotate an object, i'm not sure i can do it with rotate.

    Here is the code i use :

    Code (CSharp):
    1. float Angle = Mathf.Atan2 (Input.GetAxis ("R_StickX"), Input.GetAxis ("R_StickZ")) * Mathf.Rad2Deg;
    2.         transform.rotation = Quaternion.Euler(new Vector3(0,Angle,0));
    Thanks !
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,615
    look at RotateTowards
     
  3. bigboybifdick

    bigboybifdick

    Joined:
    Feb 8, 2014
    Posts:
    60
    Hey,

    Thanks for answering !

    I just did...
    The only thing i could come up with was :

    - a target object with no delay on the rotation (using transform.rotation)
    - my delayed object using Quaternion.RotateTowards this way :

    Code (CSharp):
    1. transform.rotation = Quaternion.RotateTowards(transform.rotation,GameObject.Find ("mytargetobject").transform.rotation , 1F * Time.deltaTime);
    It's not working.
    I dont really get why, as i can Debug.Log the target rotation, and it's actually rotating.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,615
    adjusting your code...

    Code (CSharp):
    1.  
    2. float Angle = Mathf.Atan2 (Input.GetAxis ("R_StickX"), Input.GetAxis ("R_StickZ")) * Mathf.Rad2Deg;
    3.         transform.rotation =  Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(new Vector3(0,Angle,0), 5);
     
  5. unity_RQr5MrqYB96nDw

    unity_RQr5MrqYB96nDw

    Joined:
    Jul 13, 2020
    Posts:
    3
    Thanks this helps
     
unityunity