void Start() { if (!sensor) { var sensorObj = new GameObject("HeadTrackSensor"); sensor = sensorObj.AddComponent <vHeadTrackSensor>(); } vchar = GetComponent <vICharacter>(); sensor.headTrack = this; animator = GetComponentInParent <Animator>(); head = animator.GetBoneTransform(HumanBodyBones.Head); spine1 = animator.GetBoneTransform(HumanBodyBones.Spine); spine2 = animator.GetBoneTransform(HumanBodyBones.Chest); spines = new List <Transform>(); spines.Add(spine1); spines.Add(spine2); neck = animator.GetBoneTransform(HumanBodyBones.Neck); if (neck == null) { Debug.LogWarning("Invector Headtrack Warning - Check your Character Avatar to see if a Neck Bone was assign correctly."); } if (neck.parent != spine2) { spines.Add(neck.parent); } if (head) { headHeight = Vector3.Distance(transform.position, head.position); sensor.transform.position = head.transform.position; } else { sensor.transform.position = transform.position; } var layer = LayerMask.NameToLayer("HeadTrack"); sensor.transform.parent = transform; sensor.gameObject.layer = layer; sensor.gameObject.tag = transform.tag; tagsHash = new List <int>(); for (int i = 0; i < animatorTags.Count; i++) { tagsHash.Add(Animator.StringToHash(animatorTags[i])); } GetLookPoint(); }
void Start() { if (!sensor) { var sensorObj = new GameObject("HeadTrackSensor"); sensor = sensorObj.AddComponent <vHeadTrackSensor>(); } // updates the headtrack using the late update of the tpinput so we don't need to create another one var tpInput = GetComponent <vThirdPersonInput>(); if (tpInput) { tpInput.onLateUpdate -= UpdateHeadTrack; tpInput.onLateUpdate += UpdateHeadTrack; } vchar = GetComponent <vICharacter>(); sensor.headTrack = this; animator = GetComponentInChildren <Animator>(); if (animator) { animatorStateInfos = new vAnimatorStateInfos(animator); animatorStateInfos.RegisterListener(); } if (autoFindBones) { head = animator.GetBoneTransform(HumanBodyBones.Head); if (head) { forwardReference = new GameObject("FWRF").transform; forwardReference.SetParent(head); forwardReference.transform.localPosition = Vector3.zero; forwardReference.transform.rotation = transform.rotation; var hips = animator.GetBoneTransform(HumanBodyBones.Hips); if (hips) { var target = head; for (int i = 0; i < 4; i++) { if (target.parent && target.parent.gameObject != hips.gameObject) { spine.Add(target.parent); target = target.parent; } else { break; } } } } } cameraMain = Camera.main; if (head) { headHeight = Vector3.Distance(transform.position, head.position); sensor.transform.position = head.transform.position; } else { headHeight = 1f; sensor.transform.position = transform.position; } if (spine.Count == 0) { Debug.Log("Headtrack Spines missing"); } var layer = LayerMask.NameToLayer("HeadTrack"); sensor.transform.parent = transform; sensor.gameObject.layer = layer; sensor.gameObject.tag = transform.tag; spine.Reverse(); GetLookPoint(); }