Search Unity

Trying to rotate bones via script, rotating around wrong axes

Discussion in 'Animation' started by Xenon42, Aug 17, 2018.

  1. Xenon42

    Xenon42

    Joined:
    Aug 31, 2016
    Posts:
    15
    I've been trying to make a turret script, that can animate a tank turret traversing horizontally, and pitching its gun up and down. I've made a script that works perfectly for nested gameobjects. But as soon as I try to apply the script to an animation rig, the bones start rotating in undesirable ways.

    I created my rig in Blender, and am aware that this tends to lead to weird behaviour due to the differences between how Blender and Unity handle coordinates. I have used this addon to fix my model's rotations, and while the addon appears to have worked, the turret bones are still rotating around the wrong axes.

    What can I do to make my model turret work properly?


    Here's the script I'm using: https://pastebin.com/raw/4ZGZtWHY
    The turret script is working near-perfectly, by the by. It's finding the target just fine, and rotating the bones to stay focused on it. It's just that the bones are rotating the wrong way, which is what I want to fix.

    Here's some images showing what's happening:
    In editor


    In-game, mid-rotation