Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- //add IK to the first layer in the Animator controller and add a second layer with IK enabled to control the arms
- public class AimIK : MonoBehaviour
- {
- [Header ("IK Transform References")]
- public Transform ikReference = null;
- public Transform leftHandle = null;
- public Transform rightHandle = null;
- private Vector3 target;
- private Animator animator;
- [Header("IK Weight Values")]
- [Range(0,1)]
- public float aimWeight;
- public float aimAdjustment, bodyWeight, headWeight, eyesWeight, clampWeight;
- // Use this for initialization
- void Start ()
- {
- animator = GetComponent<Animator> ();
- }
- void OnAnimatorIK (int layerIndex)
- {
- target = ikReference.position;
- target.y = target.y + aimAdjustment;
- animator.SetLookAtPosition (target);
- animator.SetLookAtWeight (aimWeight, bodyWeight, headWeight, eyesWeight, clampWeight);
- if (leftHandle != null) {
- animator.SetIKPosition (AvatarIKGoal.LeftHand, leftHandle.transform.position);
- animator.SetIKRotation (AvatarIKGoal.LeftHand, leftHandle.transform.rotation);
- animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, aimWeight);
- animator.SetIKRotationWeight (AvatarIKGoal.LeftHand, aimWeight);
- }
- if (rightHandle != null) {
- animator.SetIKPosition (AvatarIKGoal.RightHand, rightHandle.transform.position);
- animator.SetIKRotation (AvatarIKGoal.RightHand, rightHandle.transform.rotation);
- animator.SetIKPositionWeight (AvatarIKGoal.RightHand, aimWeight);
- animator.SetIKRotationWeight (AvatarIKGoal.RightHand, aimWeight);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement