Quantcast
Channel: Questions in topic: "weight"
Viewing all articles
Browse latest Browse all 136

How to smooth the animator.SetIKPositionWeight?

$
0
0
Hello there, i have a c# script that controls the hands of my character. In the specific case, when the player is near a wall (the distance is detected with a raycast), he put his hands on that wall, in the exact point where the raycast happens. The system works, but i'm trying now to smooth the movement of the hands, so that it looks smoother and more realistic. Here's the code: using UnityEngine; using System; using System.Collections; [RequireComponent(typeof(Animator))] public class IKCtrl : MonoBehaviour { public Vector3 IKtarget = Vector3.zero; protected Animator animator; public bool ikActive = false; void Start () { animator = GetComponent(); } //a callback for calculating IK void OnAnimatorIK() { if(animator) { //if the IK is active, set the position and rotation directly to the goal. if(ikActive) { animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,1.0f); animator.SetIKRotationWeight(AvatarIKGoal.LeftHand,1.0f); var handRotation = Quaternion.LookRotation(IKtarget - transform.position); animator.SetIKRotation(AvatarIKGoal.LeftHand, handRotation); animator.SetIKPosition(AvatarIKGoal.LeftHand,IKtarget); } } } } How can i do that? Since i'm a newbie, i would really appreciate specific examples. Thanks for your help! Matt Edit: Now i'm using the following function, with no results: ikweight = Mathf.Lerp(0.0f, 1f, Time.time); animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,ikweight); and ikweight = Mathf.Lerp(1.0f, 0.0f, Time.time); animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,ikweight); The second one seem to work for a while when i start the program. I'm confused :S

Viewing all articles
Browse latest Browse all 136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>