Exemplo n.º 1
0
    void UpdateHand(AvatarIKGoal goal, Transform targetTransform)
    {
        animator.SetIKPositionWeight(goal, 1);
        animator.SetIKPosition(goal, targetTransform.position);

        animator.SetIKRotationWeight(goal, 1);
        animator.SetIKRotation(goal, targetTransform.rotation);
    }
 void SetIK(Transform target, AvatarIKGoal ik_goal)
 {
     if (target != null)
     {
         animator.SetIKPosition(ik_goal, target.position);
         animator.SetIKRotation(ik_goal, target.rotation);
     }
 }
Exemplo n.º 3
0
 void Start()
 {
     animator = GetComponent<Animator>();
     if (rightHand) {
         hand = AvatarIKGoal.RightHand;
     } else {
         hand = AvatarIKGoal.LeftHand;
     }
 }
    void Bind(AvatarIKGoal ikType, Transform goal, Vector3 offset)
    {
        animator.SetIKPositionWeight(ikType, 1);
        animator.SetIKRotationWeight(ikType, 1);

        Vector3 n = goal.rotation * offset;

        animator.SetIKPosition(ikType, goal.position + n);
        animator.SetIKRotation(ikType, goal.rotation);
    }
Exemplo n.º 5
0
 /// <summary>
 /// Gets the limb solver for the %IK Goal.
 /// </summary>
 /// <returns>
 /// The solver.
 /// </returns>
 /// <param name='goal'>
 /// %IK Goal.
 /// </param>
 public IKSolverLimb GetGoalIK(AvatarIKGoal goal)
 {
     switch(goal) {
     case AvatarIKGoal.LeftFoot: return solvers.leftFoot;
     case AvatarIKGoal.RightFoot: return solvers.rightFoot;
     case AvatarIKGoal.LeftHand: return solvers.leftHand;
     case AvatarIKGoal.RightHand: return solvers.rightHand;
     }
     return null;
 }
Exemplo n.º 6
0
    void Start()
    {
        ownHand = AvatarIKGoal.LeftHand;
        animator = GetComponent<Animator>();
        navAgent = GetComponent<NavMeshAgent>();

        animator = GetComponent<Animator>();
        if (rightHand) {
            hand = AvatarIKGoal.RightHand;
        } else {
            hand = AvatarIKGoal.LeftHand;
        }
    }
Exemplo n.º 7
0
    protected void FixFoot(AvatarIKGoal footGoal, RaycastHit hit, float weight)
    {
        animator.SetIKPosition(footGoal, hit.point + (hit.normal * 0.02f));
        animator.SetIKPositionWeight(footGoal, weight);

        Quaternion q = animator.GetIKRotation(footGoal);
        Vector3 up = q * Vector3.up;

        q = Quaternion.FromToRotation(up, hit.normal) * q;

        animator.SetIKRotation(footGoal, q);
        animator.SetIKRotationWeight(footGoal, weight);
    }
Exemplo n.º 8
0
 public void SetRotation(AvatarIKGoal hand, TimelineItemData.Hand.Rotation rot)
 {
     switch (hand)
     {
         case AvatarIKGoal.LeftHand:
             desiredRotationLeft = rot;
             break;
         case AvatarIKGoal.RightHand:
             desiredRotationLeft = rot;
             break;
         default:
             break;
     }
 }
Exemplo n.º 9
0
	/****************************************/
	public bool IsActive(AvatarIKGoal foot_id)
	{

		if(foot_id == AvatarIKGoal.LeftFoot)
		{
			return mLeftFootActive;
		}
		
		if(foot_id == AvatarIKGoal.RightFoot)
		{
			return mRightFootActive;
		}

		return false;
	}
    public override void Start()
    {
        base.Start ();
        Goal = goal;

        //fist raycast to find where is the contact point
        float distance = Vector3.Distance (member.position, objectGoal.position);
        Vector3 direction = (objectGoal.position - member.position) / distance;

        RaycastHit hit;
        Physics.Raycast (member.position, direction, out hit, Mathf.Infinity);

        if (hit.transform != null) {
            distancePos = hit.point - objectGoal.position;
        }
    }
Exemplo n.º 11
0
	//Functions
	/******************************************************/
	public void SetActive(AvatarIKGoal foot_id, bool active)
	{

		if(foot_id == AvatarIKGoal.LeftFoot)
		{
			if(mLeftFoot == null)
			{
				return;
			}

			if(active)
			{
				if(!mLeftFootActive)
				{
					ResetIKParams(foot_id);
				}
			}
			mLeftFootActive = active;
		}

		if(foot_id == AvatarIKGoal.RightFoot)
		{
			if(mRightFoot == null)
			{
				return;

			}

			if(active)
			{
				if(!mRightFootActive)
				{
					ResetIKParams(foot_id);
				}
			}
			mRightFootActive = active;
		}
	}
Exemplo n.º 12
0
		/// <summary>
		/// Gets the %IK rotation weight.
		/// </summary>
		/// <param name='goal'>
		/// IK Goal.
		/// </param>
		public float GetIKRotationWeight(AvatarIKGoal goal) {
			return GetGoalIK(goal).GetIKRotationWeight();
		}
Exemplo n.º 13
0
		/// <summary>
		/// Sets the %IK position.
		/// </summary>
		/// <param name='goal'>
		/// %IK Goal.
		/// </param>
		/// <param name='IKPosition'>
		/// Position.
		/// </param>
		public void SetIKPosition(AvatarIKGoal goal, Vector3 IKPosition) {
			GetGoalIK(goal).SetIKPosition(IKPosition);
		}
Exemplo n.º 14
0
 public Vector3 GetIKPosition(AvatarIKGoal goal)
 {
     this.CheckIfInIKPass();
     return(this.GetIKPositionInternal(goal));
 }
Exemplo n.º 15
0
        }                                // 0x00000001809ECD10-0x00000001809ECDA0

        public IKSolverLimb(AvatarIKGoal goal)
        {
        }                                                 // 0x00000001809ECC70-0x00000001809ECD10
Exemplo n.º 16
0
	/*************************************************************************************************/
	protected void SetIKWeight(AvatarIKGoal foot_id, float target_weight, float transition_time)
	{
		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			if(Mathf.Abs(target_weight - mLeftFoot.GetTargetFootWeight()) > mEpsilon)//to create linear motion and the blend speed should not be calculated if the condition is not true
			{
				if(transition_time != 0)
				{
					mLeftFoot.SetGoalBlendSpeed((target_weight - mLeftFoot.GetCurrentFootWeight())/transition_time);
				}
				else
				{
					mLeftFoot.SetGoalBlendSpeed(0.1f);
					mLeftFoot.SetCurrentFootWeight(target_weight);
				}
			}
			mLeftFoot.SetTargetFootWeight(target_weight);
			break;


		case AvatarIKGoal.RightFoot:
			if(Mathf.Abs(target_weight - mRightFoot.GetTargetFootWeight()) > mEpsilon)//to create linear motion and the blend speed should not be calculated if the condition is not true
			{
				if(transition_time != 0)
				{
					mRightFoot.SetGoalBlendSpeed((target_weight - mRightFoot.GetCurrentFootWeight())/transition_time);
				}
				else
				{
					mRightFoot.SetGoalBlendSpeed(0.1f);
					mRightFoot.SetCurrentFootWeight(target_weight);
				}
			}
			mRightFoot.SetTargetFootWeight(target_weight);
			break;
		}
	}
Exemplo n.º 17
0
 private static extern void INTERNAL_CALL_GetIKRotationInternal(Animator self, AvatarIKGoal goal, out Quaternion value);
Exemplo n.º 18
0
 public void SetIKRotationWeight(AvatarIKGoal goal, float value)
 {
     this.CheckIfInIKPass();
     this.SetIKRotationWeightInternal(goal, value);
 }
Exemplo n.º 19
0
 public void NetWorkSetIKRotationWeight(AvatarIKGoal goal, float value)
 {
     m_animator.SetIKRotationWeight(goal, value);
 }
Exemplo n.º 20
0
 public float GetIKRotationWeight(AvatarIKGoal goal)
 {
     this.CheckIfInIKPass();
     return(this.GetIKRotationWeightInternal(goal));
 }
Exemplo n.º 21
0
 internal extern float GetIKRotationWeightInternal(AvatarIKGoal goal);
Exemplo n.º 22
0
 private static extern void INTERNAL_CALL_SetIKRotationInternal(Animator self, AvatarIKGoal goal, ref Quaternion goalRotation);
Exemplo n.º 23
0
 internal void SetIKRotationInternal(AvatarIKGoal goal, Quaternion goalRotation)
 {
     Animator.INTERNAL_CALL_SetIKRotationInternal(this, goal, ref goalRotation);
 }
Exemplo n.º 24
0
 public void SetIKRotation(AvatarIKGoal goal, Quaternion goalRotation)
 {
     this.CheckIfInIKPass();
     this.SetIKRotationInternal(goal, goalRotation);
 }
Exemplo n.º 25
0
 // Use this for initialization
 void Start()
 {
     ownHand = AvatarIKGoal.LeftHand;
     animator = GetComponent<Animator>();
     navAgent = GetComponent<NavMeshAgent>();
 }
Exemplo n.º 26
0
 internal extern void SetIKRotationWeightInternal(AvatarIKGoal goal, float value);
Exemplo n.º 27
0
 public void NetWorkSetIKRotation(AvatarIKGoal goal, Quaternion goalPosition)
 {
     m_animator.SetIKRotation(goal, goalPosition);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Detachs the hand from handle, if the IK is not active, set the position and rotation of the hand and head back to the original position
 /// </summary>
 /// <param name="hand">Hand.</param>
 protected virtual void DetachHandFromHandle(AvatarIKGoal hand)
 {
     _animator.SetIKPositionWeight(hand, 0);
     _animator.SetIKRotationWeight(hand, 0);
     _animator.SetLookAtWeight(0);
 }
Exemplo n.º 29
0
	/***************************************************************/
	public void DisablePlant(AvatarIKGoal foot_id, float blend_speed)
	{
		FootPlacementData lFoot;

		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;
			
		default:
			return;
		}
		
		lFoot.DisablePlantBlend(blend_speed);
	}
 public Vector3 GetGoalPosition(AvatarIKGoal index)
 {
     this.ThrowIfInvalid();
     return(this.InternalGetGoalPosition(index));
 }
Exemplo n.º 31
0
	/*************************************************/
	protected void CheckForLimits(AvatarIKGoal foot_id)
	{
		FootPlacementData lFoot;

		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;
			
		default:
			return;
		}

		//To check pitch limit of foot
		Vector3 lExtraOffset = Vector3.zero;
		Vector3 lRotatedFwdVec = lFoot.GetRotatedFwdVec();
		
		if(Vector3.Angle(lRotatedFwdVec, lFoot.GetTargetPos(FootPlacementData.Target.TOE)) > lFoot.mFootRotationLimit)
		{
			lExtraOffset = lFoot.mUpVector * lFoot.mFootLength * Mathf.Tan(lFoot.mFootRotationLimit * (Mathf.PI/180));

			if(Vector3.Angle(lFoot.mUpVector, lFoot.GetTargetPos(FootPlacementData.Target.TOE)) > 90)
			{
				lExtraOffset = -lExtraOffset;
			}

			lFoot.SetTargetPos(FootPlacementData.Target.TOE, (lRotatedFwdVec * lFoot.mFootLength) + lExtraOffset);
		}

		Quaternion lQuat90 = new Quaternion(0, 0.7071f, 0, 0.7071f);

		//To check roll limit of foot
		if(Vector3.Angle(lQuat90 * lRotatedFwdVec, lFoot.GetTargetPos(FootPlacementData.Target.HEEL)) > lFoot.mFootRotationLimit)
		{
			lExtraOffset = lFoot.mUpVector * lFoot.mFootHalfWidth * Mathf.Tan(lFoot.mFootRotationLimit * (Mathf.PI/180));
			
			if(Vector3.Angle(lFoot.mUpVector, lFoot.GetTargetPos(FootPlacementData.Target.HEEL)) > 90)
			{
				lExtraOffset = -lExtraOffset;
			}
			lFoot.SetTargetPos(FootPlacementData.Target.HEEL, (lQuat90 * lRotatedFwdVec * lFoot.mFootHalfWidth) + lExtraOffset);
		}
	}
 public void SetGoalPosition(AvatarIKGoal index, Vector3 pos)
 {
     this.ThrowIfInvalid();
     this.InternalSetGoalPosition(index, pos);
 }
Exemplo n.º 33
0
 private static extern void INTERNAL_CALL_SetIKPositionInternal(Animator self, AvatarIKGoal goal, ref Vector3 goalPosition);
 public Quaternion GetGoalRotation(AvatarIKGoal index)
 {
     this.ThrowIfInvalid();
     return(this.InternalGetGoalRotation(index));
 }
Exemplo n.º 35
0
 private void SetSocketIK(AvatarIKGoal goal, Transform socket, Vector3 offset)
 {
     SetSocketIK(goal, socket.position, socket.rotation, offset);
 }
 public void SetGoalRotation(AvatarIKGoal index, Quaternion rot)
 {
     this.ThrowIfInvalid();
     this.InternalSetGoalRotation(index, rot);
 }
Exemplo n.º 37
0
		/// <summary>
		/// Gets the %IK rotation.
		/// </summary>
		/// <param name='goal'>
		/// %IK Goal.
		/// </param>
		public Quaternion GetIKRotation(AvatarIKGoal goal) {
			return GetGoalIK(goal).GetIKRotation();
		}
 public void SetGoalWeightRotation(AvatarIKGoal index, float value)
 {
     this.ThrowIfInvalid();
     this.InternalSetGoalWeightRotation(index, value);
 }
Exemplo n.º 39
0
		/// <summary>
		/// Sets the %IK rotation weight.
		/// </summary>
		/// <param name='goal'>
		/// %IK Goal.
		/// </param>
		/// <param name='weight'>
		/// Weight.
		/// </param>
		public void SetIKRotationWeight(AvatarIKGoal goal, float weight) {
			GetGoalIK(goal).SetIKRotationWeight(weight);
		}
 public float GetGoalWeightRotation(AvatarIKGoal index)
 {
     this.ThrowIfInvalid();
     return(this.InternalGetGoalWeightRotation(index));
 }
Exemplo n.º 41
0
		/// <summary>
		/// Sets the %IK rotation.
		/// </summary>
		/// <param name='goal'>
		/// %IK Goal.
		/// </param>
		/// <param name='IKRotation'>
		/// Rotation.
		/// </param>
		public void SetIKRotation(AvatarIKGoal goal, Quaternion IKRotation) {
			GetGoalIK(goal).SetIKRotation(IKRotation);
		}
 private void InternalSetGoalPosition(AvatarIKGoal index, Vector3 pos)
 {
     AnimationHumanStream.InternalSetGoalPosition_Injected(ref this, index, ref pos);
 }
Exemplo n.º 43
0
		public IKSolverLimb(AvatarIKGoal goal) {
			this.goal = goal;
		}
 private void InternalSetGoalRotation(AvatarIKGoal index, Quaternion rot)
 {
     AnimationHumanStream.InternalSetGoalRotation_Injected(ref this, index, ref rot);
 }
Exemplo n.º 45
0
 public TimelineItemData.Hand.Rotation GetRotation(AvatarIKGoal hand)
 {
     return hand == AvatarIKGoal.LeftHand ? rotationLeft : rotationRight;
 }
Exemplo n.º 46
0
	/*****************************************************/
	public float GetPlantBlendWeight(AvatarIKGoal foot_id)
	{
		FootPlacementData lFoot;
		
		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;
			
		default:
			return -1;
		}

		return lFoot.GetPlantBlendFactor();
	}
Exemplo n.º 47
0
	/******************************************************************/
	public void SetPlantBlendWeight(AvatarIKGoal foot_id, float weight)
	{
		FootPlacementData lFoot;
		
		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;
			
		default:
			return;
		}
		
		lFoot.SetPlantBlendFactor(weight);
	}
Exemplo n.º 48
0
 public void NetWorkSetIKPosition(AvatarIKGoal goal, Vector3 goalPosition)
 {
     m_animator.SetIKPosition(goal, goalPosition);
 }
Exemplo n.º 49
0
	/**********************************************/
	private void ResetIKParams(AvatarIKGoal foot_id)
	{

		if(foot_id == AvatarIKGoal.LeftFoot)
		{
			Vector3 lFootPos = mAnim.GetBoneTransform(HumanBodyBones.LeftFoot).position;

			mLeftFoot.SetTargetFootWeight(0);
			mLeftFoot.SetCurrentFootWeight(0);
			mLeftFoot.SetGoalBlendSpeed(0);
			mLeftFoot.SetFootPlanted(false);

			mLeftFootContact_Ontransition_Disable = lFootPos;
			mLeftToeContact_Ontransition_Disable = mLeftFoot.mUpVector * mLeftFoot.mFootOffsetDist + mLeftFoot.GetRotatedFwdVec() * mLeftFoot.mFootLength;
			mLeftHeelContact_Ontransition_Disable = lFootPos + new Quaternion(0, 0.7071f, 0, 0.7071f) * mLeftFoot.GetRotatedFwdVec() * mLeftFoot.mFootHalfWidth;

		}

		if(foot_id == AvatarIKGoal.RightFoot)
		{
			Vector3 lFootPos = mAnim.GetBoneTransform(HumanBodyBones.RightFoot).position;

			mRightFoot.SetTargetFootWeight(0);
			mRightFoot.SetCurrentFootWeight(0);
			mRightFoot.SetGoalBlendSpeed(0);
			mRightFoot.SetFootPlanted(false);

			mRightFootContact_Ontransition_Disable = lFootPos;
			mRightToeContact_Ontransition_Disable = mRightFoot.mUpVector * mLeftFoot.mFootOffsetDist + mRightFoot.GetRotatedFwdVec() * mRightFoot.mFootLength;
			mRightHeelContact_Ontransition_Disable = lFootPos + new Quaternion(0, 0.7017f, 0, 0.7071f) * mRightFoot.GetRotatedFwdVec() * mRightFoot.mFootHalfWidth;
		}
	}
Exemplo n.º 50
0
	/***************************************************************/
	protected void UpdateFootPlantBlendWeights(AvatarIKGoal foot_id)
	{
		FootPlacementData lFoot;

		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;
			
		default:
			return;
		}

		if(lFoot.IsPlantOnTransition())
		{
			lFoot.SetPlantBlendFactor(lFoot.GetPlantBlendFactor() + lFoot.GetFootPlantBlendSpeed() * Time.deltaTime);
			
			if(lFoot.GetFootPlantBlendSpeed() > 0) //enbale foot plant
			{
				if(lFoot.GetPlantBlendFactor() > 1)
				{
					lFoot.SetPlantBlendFactor(1);
					lFoot.PlantBlendTransitionEnded();
				}
			}
			else
			{
				if(lFoot.GetPlantBlendFactor() < 0) // disable foot plant
				{
					lFoot.SetPlantBlendFactor(0);
					lFoot.PlantBlendTransitionEnded();
				}
			}
			
		}
	}
Exemplo n.º 51
0
	/*********************************************************/
	protected void CalculateIKGoalWeights(AvatarIKGoal foot_id)
	{
		FootPlacementData lFoot;

		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
		
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;

		default:
			return;
		}
		

		float lSign = Mathf.Sign(lFoot.GetTargetFootWeight() - lFoot.GetCurrentFootWeight());
		lFoot.SetCurrentFootWeight( lFoot.GetCurrentFootWeight() + lFoot.GetGoalBlendSpeed() * Time.deltaTime);

		if(lSign * Mathf.Sign(lFoot.GetTargetFootWeight() - lFoot.GetCurrentFootWeight()) < 1 ||
		  Mathf.Abs(lFoot.GetCurrentFootWeight() - lFoot.GetTargetFootWeight()) < mEpsilon)
		{
			lFoot.SetCurrentFootWeight(lFoot.GetTargetFootWeight());
			return;
		}

		if(lFoot.GetCurrentFootWeight() > 1 || lFoot.GetCurrentFootWeight() < 0)
		{
			lFoot.SetCurrentFootWeight(lFoot.GetTargetFootWeight());
		}
	}
Exemplo n.º 52
0
	/*********************************************/
	public void FootPlacement(AvatarIKGoal foot_id)
	{

		FootPlacementData lFoot = null;

		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			if(!mLeftFootActive)
			{
				return;
			}
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			if(!mRightFootActive)
			{
				return;
			}
			lFoot = mRightFoot;
			break;
			
		default:
			return;
		}

		lFoot.mUpVector.Normalize();
		lFoot.mForwardVector.Normalize();

		//Update forward vec and IKHintoffset based on cahracter foot and body rotation
		lFoot.CalculateRotatedIKHint();
		lFoot.CalculateRotatedFwdVec();

		//Updating Plant Foot Blend Transitions
		UpdateFootPlantBlendWeights(foot_id);

		//Find exact contact points
		FindContactPoints(foot_id);
		
		//Check for feet limits
		CheckForLimits(foot_id);

		//Update IK goal weights
		CalculateIKGoalWeights(foot_id);
		
		/*Setup Final IK Rotaiton*/
		mAnim.SetIKRotationWeight(foot_id, lFoot.GetCurrentFootWeight());


		//converting the foot yaw rotation to degree
		float lAngle = Vector3.Angle(lFoot.GetRotatedFwdVec(), lFoot.mForwardVector);

		Quaternion lQuat90 = new Quaternion(0, 0.7071f, 0, 0.7071f);
		Vector3 lEulerRot = Quaternion.FromToRotation(lFoot.mForwardVector, lFoot.GetTargetPos(FootPlacementData.Target.TOE)).eulerAngles;
		lEulerRot.z = 0;
		Quaternion lRot = Quaternion.Euler(lEulerRot);
		if((lAngle > 90 && lAngle < 180)  || (lAngle > 270 && lAngle < 90))
		{
			lEulerRot = Quaternion.FromToRotation(lFoot.GetTargetPos(FootPlacementData.Target.HEEL), lQuat90 *  lFoot.GetRotatedFwdVec()).eulerAngles;
		}
		else
		{
			lEulerRot = Quaternion.FromToRotation(lQuat90 *  lFoot.GetRotatedFwdVec(), lFoot.GetTargetPos(FootPlacementData.Target.HEEL)).eulerAngles;
		}

		lEulerRot.x = 0;
		lEulerRot.y = 0;
		lRot = lRot * Quaternion.Euler(lEulerRot);
		mAnim.SetIKRotation(foot_id, lRot);

		/*Setup Final IK Swivel Angle*/
		Vector3 lIKHintDir = Vector3.zero;

		if(foot_id == AvatarIKGoal.LeftFoot)
		{
			lIKHintDir = mAnim.GetBoneTransform(HumanBodyBones.LeftLowerLeg).position - mAnim.GetIKPosition(AvatarIKGoal.LeftFoot);//mAnim.GetBoneTransform(HumanBodyBones.LeftFoot).position;
			mAnim.SetIKHintPositionWeight(AvatarIKHint.LeftKnee, lFoot.GetCurrentFootWeight());

			mAnim.SetIKHintPosition(AvatarIKHint.LeftKnee, lFoot.GetTargetPos(FootPlacementData.Target.TOE) + lFoot.GetTargetPos(FootPlacementData.Target.FOOT)
			                        + lFoot.GetRotatedIKHint() + lIKHintDir);

		}

		if(foot_id == AvatarIKGoal.RightFoot)
		{
			lIKHintDir = mAnim.GetBoneTransform(HumanBodyBones.RightLowerLeg).position - mAnim.GetBoneTransform(HumanBodyBones.RightFoot).position;
			mAnim.SetIKHintPositionWeight(AvatarIKHint.RightKnee, lFoot.GetCurrentFootWeight());
			mAnim.SetIKHintPosition(AvatarIKHint.RightKnee, lFoot.GetTargetPos(FootPlacementData.Target.TOE) + lFoot.GetTargetPos(FootPlacementData.Target.FOOT)
			                        + lFoot.GetRotatedIKHint() + lIKHintDir);
		}

		/*Setup Final IK Position*/
		mAnim.SetIKPositionWeight(foot_id, lFoot.GetCurrentFootWeight());
		mAnim.SetIKPosition(foot_id, lFoot.GetTargetPos(FootPlacementData.Target.FOOT) + (lFoot.mUpVector * lFoot.mFootHeight));


		/*Update planted foot position and rotation*/
		if(lFoot.GetCurrentFootWeight() <= 0)
		{
			lFoot.SetFootPlanted(false);
		}
		else
		{
			if(lFoot.mPlantFoot && !lFoot.GetFootPlanted())
			{
				if(Mathf.Abs(lFoot.GetTargetFootWeight() - lFoot.GetCurrentFootWeight()) < mEpsilon)
				{
					lFoot.SetPlantedPos(mAnim.GetIKPosition(foot_id));//
					lFoot.SetPlantedRot(mAnim.GetIKRotation(foot_id));
					lFoot.SetFootPlanted(true);
				}
			}
		}
	}
Exemplo n.º 53
0
 public void SetIKPosition(AvatarIKGoal goal, Vector3 goalPosition)
 {
     this.CheckIfInIKPass();
     this.SetIKPositionInternal(goal, goalPosition);
 }
Exemplo n.º 54
0
 public Quaternion GetIKRotation(AvatarIKGoal goal)
 {
     this.CheckIfInIKPass();
     return(this.GetIKRotationInternal(goal));
 }
Exemplo n.º 55
0
	/****************************************************/
	protected void FindContactPoints(AvatarIKGoal foot_id)
	{
		FootPlacementData lFoot;
		Vector3 lContactPos;
		Vector3 lFootPos = mAnim.GetIKPosition(foot_id);
		bool lContactDetected = true;


		switch(foot_id)
		{
		case AvatarIKGoal.LeftFoot:
			lFoot = mLeftFoot;
			break;
			
		case AvatarIKGoal.RightFoot:
			lFoot = mRightFoot;
			break;
			
		default:
			return;
		}
	
		RaycastHit lHit;

		bool lHasCharacterController = false;
		if(GetComponent<CharacterController>() != null)
		{
			if(GetComponent<CharacterController>().enabled)
			{
				lHasCharacterController = true;
			}
		}

		if(lHasCharacterController && lFoot.mIgnoreCharacterControllerCollision)
		{
			GetComponent<CharacterController>().enabled = false;
		}

		if(Physics.Raycast(lFootPos + lFoot.mUpVector * lFoot.mFootOffsetDist, -lFoot.mUpVector, out lHit, lFoot.mFootOffsetDist + lFoot.mFootHeight + lFoot.mExtraRayDistanceCheck))
		{
			SetIKWeight(foot_id, 1, lFoot.mTransitionTime);

			{//Scope Start For lResult Var
				Vector3 lResult = lHit.point;

				if(lFoot.mPlantFoot && lFoot.GetFootPlanted())
				{
					if(Physics.Raycast(lFoot.GetPlantedPos() + lFoot.mUpVector * lFoot.mFootOffsetDist, -lFoot.mUpVector, out lHit, lFoot.mFootOffsetDist + lFoot.mFootHeight + lFoot.mExtraRayDistanceCheck))
					{
						lResult = Vector3.Lerp(lResult, lHit.point, lFoot.GetPlantBlendFactor());
					}
				}

				lFoot.SetTargetPos(FootPlacementData.Target.FOOT, lResult);
			}//Scope End

			if(foot_id == AvatarIKGoal.LeftFoot)
			{
				mLeftFootContact_Ontransition_Disable = lFoot.GetTargetPos(FootPlacementData.Target.FOOT);
			}
			else
			{
				mRightFootContact_Ontransition_Disable = lFoot.GetTargetPos(FootPlacementData.Target.FOOT);
			}
		
			lContactDetected = true;
		}
		else
		{
			SetIKWeight(foot_id, 0, lFoot.mTransitionTime);
			if(foot_id == AvatarIKGoal.LeftFoot)
			{
				lContactPos = mLeftFootContact_Ontransition_Disable;
			}
			else
			{
				lContactPos = mRightFootContact_Ontransition_Disable;
			}

			lFoot.SetTargetPos(FootPlacementData.Target.FOOT, Vector3.Lerp(lFootPos, lContactPos, lFoot.GetCurrentFootWeight()));
			lContactDetected = false;
		}

		if(Physics.Raycast(lFootPos + (lFoot.mUpVector * lFoot.mFootOffsetDist) + (lFoot.GetRotatedFwdVec() * lFoot.mFootLength), -lFoot.mUpVector, out lHit, 
		                   lFoot.mFootOffsetDist + lFoot.mFootLength + lFoot.mExtraRayDistanceCheck) && lContactDetected)
		{

			{//Scope Start For lResult Var
				Vector3 lResult = lHit.point;
				if(lFoot.mPlantFoot && lFoot.GetFootPlanted())
				{
					if(Physics.Raycast(lFoot.GetPlantedPos() + (lFoot.mUpVector * lFoot.mFootOffsetDist) + (lFoot.GetRotatedFwdVec() * lFoot.mFootLength), -lFoot.mUpVector, out lHit, 
					                lFoot.mFootOffsetDist + lFoot.mFootLength + lFoot.mExtraRayDistanceCheck))
					{
						lResult = Vector3.Lerp(lResult, lHit.point, lFoot.GetPlantBlendFactor());
					}
				}

				lFoot.SetTargetPos(FootPlacementData.Target.TOE, lResult - lFoot.GetTargetPos(FootPlacementData.Target.FOOT));
			}//Scope End
			
			if(foot_id == AvatarIKGoal.LeftFoot)             
			{
				mLeftToeContact_Ontransition_Disable = lFoot.GetTargetPos(FootPlacementData.Target.TOE);
			}
			else
			{
				mRightToeContact_Ontransition_Disable = lFoot.GetTargetPos(FootPlacementData.Target.TOE);
			}
		}
		else
		{
			if(foot_id == AvatarIKGoal.LeftFoot)
			{
				lContactPos = mLeftToeContact_Ontransition_Disable;
			}
			else
			{
				lContactPos = mRightToeContact_Ontransition_Disable;

			}

			lFoot.SetTargetPos(FootPlacementData.Target.TOE, 
			                   Vector3.Slerp(lFoot.GetRotatedFwdVec() * lFoot.mFootLength , lContactPos, lFoot.GetCurrentFootWeight()));
		}

		Quaternion lQuat90 = new Quaternion(0, 0.7071f, 0, 0.7071f);
	
		if(Physics.Raycast(lFootPos + (lFoot.mUpVector * lFoot.mFootOffsetDist) + ((lQuat90 * lFoot.GetRotatedFwdVec()).normalized * lFoot.mFootHalfWidth), -lFoot.mUpVector, out lHit, 
		                   lFoot.mFootOffsetDist + lFoot.mFootLength + lFoot.mExtraRayDistanceCheck) && lContactDetected)
		{
			{//Scope Start For lResult Var
				Vector3 lResult = lHit.point;

				if(lFoot.mPlantFoot && lFoot.GetFootPlanted())
				{
					if(Physics.Raycast(lFoot.GetPlantedPos() + (lFoot.mUpVector * lFoot.mFootOffsetDist) + ((lQuat90 * lFoot.GetRotatedFwdVec()).normalized * lFoot.mFootHalfWidth), -lFoot.mUpVector, out lHit, 
					                lFoot.mFootOffsetDist + lFoot.mFootLength + lFoot.mExtraRayDistanceCheck))
					{
						lResult = Vector3.Lerp(lResult, lHit.point, lFoot.GetPlantBlendFactor());
					}
				}

				lFoot.SetTargetPos(FootPlacementData.Target.HEEL, lResult - lFoot.GetTargetPos(FootPlacementData.Target.FOOT));
			}//Scope End

			if(foot_id == AvatarIKGoal.LeftFoot)
			{
				mLeftHeelContact_Ontransition_Disable = lFoot.GetTargetPos(FootPlacementData.Target.HEEL);

			}
			else
			{
				mRightHeelContact_Ontransition_Disable = lFoot.GetTargetPos(FootPlacementData.Target.HEEL);
			}
		}
		else
		{
			if(foot_id == AvatarIKGoal.LeftFoot)
			{
				lContactPos = mLeftHeelContact_Ontransition_Disable;
			}
			else
			{
				lContactPos = mRightHeelContact_Ontransition_Disable;
			}

			lFoot.SetTargetPos(FootPlacementData.Target.HEEL, 
			                   Vector3.Slerp((lQuat90 * lFoot.GetRotatedFwdVec() * lFoot.mFootHalfWidth), lContactPos, lFoot.GetCurrentFootWeight()));
		}

		if(lHasCharacterController && lFoot.mIgnoreCharacterControllerCollision)
		{
			GetComponent<CharacterController>().enabled = true;
		}
	}
Exemplo n.º 56
0
 private static extern void INTERNAL_CALL_GetIKPositionInternal(Animator self, AvatarIKGoal goal, out Vector3 value);
 private void InternalSetGoalWeightRotation(AvatarIKGoal index, float value)
 {
     AnimationHumanStream.InternalSetGoalWeightRotation_Injected(ref this, index, value);
 }
Exemplo n.º 58
0
 internal void SetIKPositionInternal(AvatarIKGoal goal, Vector3 goalPosition)
 {
     Animator.INTERNAL_CALL_SetIKPositionInternal(this, goal, ref goalPosition);
 }
Exemplo n.º 59
0
        void DoGetIKGoal()
        {
            if (_animator==null)
            {
                return;
            }

            _iKGoal = 	(AvatarIKGoal)iKGoal.Value;

            if (_transform!=null)
            {
                _transform.position = _animator.GetIKPosition(_iKGoal);
                _transform.rotation = _animator.GetIKRotation(_iKGoal);
            }

            if (!position.IsNone)
            {
                position.Value = _animator.GetIKPosition(_iKGoal);
            }

            if (!rotation.IsNone)
            {
                rotation.Value =_animator.GetIKRotation(_iKGoal);
            }

            if (!positionWeight.IsNone)
            {
                positionWeight.Value = _animator.GetIKPositionWeight(_iKGoal);
            }
            if (!rotationWeight.IsNone)
            {
                rotationWeight.Value = _animator.GetIKRotationWeight(_iKGoal);
            }
        }
Exemplo n.º 60
0
 public float GetIKPositionWeight(AvatarIKGoal goal)
 {
     return(m_animator.GetIKPositionWeight(goal));
 }