Files
FueraDeEscala/Assets/Kevin Iglesias/IKHelperTool/Scripts/IKHelperTool.cs

54 lines
1.8 KiB
C#
Raw Normal View History

2026-03-29 23:03:14 -07:00
///////////////////////////////////////////////////////////////////////////
// IKHelperTool //
// Kevin Iglesias - https://www.keviniglesias.com/ //
// Contact Support: support@keviniglesias.com //
///////////////////////////////////////////////////////////////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace KevinIglesias {
public enum IKHelperHand {LeftHand = 0, RightHand = 1};
public class IKHelperTool : MonoBehaviour
{
public Transform iKSwitch;
public Transform handEffector;
public IKHelperHand hand;
private Animator animator;
private float weight;
void Awake()
{
animator = GetComponent<Animator>();
weight = 0f;
}
void Update()
{
weight = Mathf.Lerp(0, 1, 1f - Mathf.Cos(iKSwitch.localPosition.y * Mathf.PI * 0.5f));
}
void OnAnimatorIK(int layerIndex)
{
if(hand == IKHelperHand.LeftHand)
{
animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, weight);
animator.SetIKPosition(AvatarIKGoal.LeftHand, handEffector.position);
animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, weight);
animator.SetIKRotation(AvatarIKGoal.LeftHand, handEffector.rotation);
}else{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, weight);
animator.SetIKPosition(AvatarIKGoal.RightHand, handEffector.position);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, weight);
animator.SetIKRotation(AvatarIKGoal.RightHand, handEffector.rotation);
}
}
}
}