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

Not rotate child when parent rotates

Discussion in 'Scripting' started by xarapuchatok, Mar 5, 2020.

  1. xarapuchatok

    xarapuchatok

    Joined:
    Dec 27, 2019
    Posts:
    11
    Hi everyone! I am trying to make script for tank! And my problem is when I rotate turret on target it rotates normaly but when at the moment "on aiming" I rotate base turret rotates with the base and then begin to LookAt target again. How can I rotate base and not rotate turret! Is there something like
    Code (CSharp):
    1. transform.parent.rotation = null;
     
  2. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    449
    You could - when rotating the base - first get the world rotation of the turret, then update the rotation of the base and then reapply the previously cached world rotation of the turret.
    Your current issue might be that the turret code (look at) is updated before the base code and therefor it has the wrong rotation for one frame.
     
  3. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    424
    Or don't have the turret as a physical child (have both a child of a container object), and just have it inherit transforms when it's needed.
     
  4. xarapuchatok

    xarapuchatok

    Joined:
    Dec 27, 2019
    Posts:
    11
    I have 2 different cripts on base and turret
     
  5. FlashMuller

    FlashMuller

    Joined:
    Sep 25, 2013
    Posts:
    449
    Try changing the script execution order.