Trouble referencing a bone. Even though animations working fine and Avatar imported skelton very satsifactorily
Hi all, I've been working away on a 3d game with an army guy running around shooting stuff.
I've got mocaps from the asset store that work with my model and he runs about fine now, but I have a gameObject called TriggerFingerPoint that I need to follow the trigger finger of the model , and then I have the GunTriggerPoint, which i want to attach to that bone.
Hope that makes sense... I couldnt find out how to do this with the unity docs im sad to say.
BTW: this is what i tried so far, but it seems like it thinks "hand_r" doesnt exist because that line throws a null exception
private void Start()
{
rb = GetComponent<Rigidbody>();
playerAnims = GetComponentInChildren<PlayerAnimations>();
absoluteGround = rb.transform.position.y;
distToGround = GetComponent<Collider>().bounds.extents.y;
gunTriggerPoint = GameObject.FindGameObjectWithTag("GunTriggerPoint");
gunTriggerPoint.transform.SetParent(GameObject.Find("hand_r").transform);
gunTriggerPoint.transform.position = new Vector3(0, 0, 0);
gunTriggerPoint.transform.rotation = Quaternion.identity;
}
I've also now tried this and the null exception has gone, but if I try to something like (gunTriggerPoint.transform.position = handR.position; (I also tried handR.transform.position), then I get null reference error.
new code:
Transform handR;
private void Start()
{
rb = GetComponent<Rigidbody>();
playerAnims = GetComponentInChildren<PlayerAnimations>();
absoluteGround = rb.transform.position.y;
distToGround = GetComponent<Collider>().bounds.extents.y;
gunTriggerPoint = GameObject.FindGameObjectWithTag("GunTriggerPoint");
handR = transform.Find("hand_r");
gunTriggerPoint.transform.SetParent(handR);
gunTriggerPoint.transform.position = new Vector3(0, 0, 0);
gunTriggerPoint.transform.rotation = Quaternion.identity;
}
Also, the gun even though now parented doesnt follow the player, and rather floats in mid air doing nothing
Further note: The gun has no parent. I checked in the heirarchy. I also tried just instantiating a new gun and setting parent, it made no difference
Also, the gun even though now parented doesnt follow the player, and rather floats in mid air doing nothing