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

Why will bones not copy location of other bones?

Discussion in 'Scripting' started by Sporech, Oct 16, 2015.

  1. Sporech

    Sporech

    Joined:
    Sep 14, 2015
    Posts:
    26
    I have a very simple script which will make the hands of a humanoid rig copy locations of different parts of a gun, but it doesn't do anything (even error)!
    Can anyone see any problems:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class WeaponHold : MonoBehaviour {
    5.     public GameObject lefthand;
    6.     public GameObject righthand;
    7.     public GameObject pump;
    8.     public GameObject trigger;
    9.  
    10.     void Start () {
    11.        
    12.     }
    13.  
    14.     void Update () {
    15.         Vector3 pumplocation = new Vector3 (pump.transform.position.x, pump.transform.position.y, pump.transform.position.z);
    16.         Vector3 triggerlocation = new Vector3 (trigger.transform.position.x, trigger.transform.position.y, trigger.transform.position.z);
    17.         lefthand.transform.position = pumplocation;
    18.         righthand.transform.position = triggerlocation;
    19.     }
    20. }
    21.  
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Are lefthand and righthand affected by an Animator? IIRC Animator updates in between Update and LateUpdate, so it may simply be overwriting your position changes.

    (If they are children of an object that has an Animator, they may be affected even if the currently playing clip doesn't touch them. If an Animator has clips A, B, C, and D, and only clip C affects the position of object X, then when clips A, B, and D are playing, the Animator will force object X to its default position.)
     
  3. Sporech

    Sporech

    Joined:
    Sep 14, 2015
    Posts:
    26
    Okay, makes sense. How do i tag an object to have animator?
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Huh?
     
    ThermalFusion likes this.
  5. Sporech

    Sporech

    Joined:
    Sep 14, 2015
    Posts:
    26
    Well, in other words; how do i make them affected by an animator (i'm not good with terminology, sorry :p)
     
  6. Sporech

    Sporech

    Joined:
    Sep 14, 2015
    Posts:
    26
    Nevermind, i got it working; i assigned the wrong bones to lefthand and righthand! Dammit XD. My friend makes the models and the ones i used i didn't know were actually nothing more than transforms and not part of the rig.
     
    ThermalFusion likes this.