Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LerpIKHands_Direct()
- {
- if (enableRootMovement)
- _ikT += Time.deltaTime * 5;
- if (_ikT > 1)
- {
- _ikT = 1;
- ikLandSideReached = true;
- }
- Vector3 lhPosition = Vector3.LerpUnclamped(_ikStartPos[0], _ikTargetPos[0], _ikT);
- ik.UpdateTargetPosition(AvatarIKGoal.LeftHand, lhPosition);
- Vector3 rhPosition = Vector3.LerpUnclamped(_ikStartPos[2], _ikTargetPos[2], _ikT);
- ik.UpdateTargetPosition(AvatarIKGoal.RightHand, rhPosition);
- }
- void LerpIKFeet_Direct()
- {
- if (targetPoint.pointType == PointType.hanging)
- {
- ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
- ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
- }
- else
- {
- if (enableRootMovement)
- _fikT += Time.deltaTime * 5;
- if (_fikT > 1)
- {
- _fikT = 1;
- ikFollowSideReached = true;
- }
- Vector3 lfPosition = Vector3.LerpUnclamped(_ikStartPos[1], _ikTargetPos[1], _fikT);
- ik.UpdateTargetPosition(AvatarIKGoal.LeftFoot, lfPosition);
- Vector3 rfPosition = Vector3.LerpUnclamped(_ikStartPos[3], _ikTargetPos[3], _fikT);
- ik.UpdateTargetPosition(AvatarIKGoal.RightFoot, rfPosition);
- }
- }
- void LerpIKLandingSide_Direct()
- {
- if (enableRootMovement)
- _ikT += Time.deltaTime * 3.2f;
- if (_ikT > 1)
- {
- _ikT = 1;
- ikLandSideReached = true;
- }
- Vector3 landPosition = Vector3.LerpUnclamped(_ikStartPos[0], _ikTargetPos[0], _ikT);
- ik.UpdateTargetPosition(ik_L, landPosition);
- if (targetPoint.pointType == PointType.hanging)
- {
- ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
- ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
- }
- else
- {
- Vector3 followPosition = Vector3.LerpUnclamped(_ikStartPos[1], _ikTargetPos[1], _ikT);
- ik.UpdateTargetPosition(ik_F, followPosition);
- }
- }
- void LerpIKFollowSide_Direct()
- {
- if (enableRootMovement)
- _fikT += Time.deltaTime * 2.6f;
- if (_fikT > 1)
- {
- _fikT = 1;
- ikFollowSideReached = true;
- }
- Vector3 landPosition = Vector3.LerpUnclamped(_ikStartPos[2], _ikTargetPos[2], _fikT);
- ik.UpdateTargetPosition(ik.ReturnOppositeIK(ik_L), landPosition);
- if (targetPoint.pointType == PointType.hanging)
- {
- ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
- ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
- }
- else
- {
- Vector3 followPosition = Vector3.LerpUnclamped(_ikStartPos[3], _ikTargetPos[3], _fikT);
- ik.UpdateTargetPosition(ik.ReturnOppositeIK(ik_F), followPosition);
- }
- }
- AvatarIKGoal ik_L; //ik for the landing side
- AvatarIKGoal ik_F; //ik for the following side
- float _ikT;
- float _fikT;
- Vector3[] _ikStartPos = new Vector3[4];
- Vector3[] _ikTargetPos = new Vector3[4];
- void InitIK(Vector3 directionToPoint, bool opposite)
- {
- Vector3 relativeDirection = transform.InverseTransformDirection(directionToPoint);
- if (Mathf.Abs(relativeDirection.y) > 0.5f)
- {
- float targetAnim = 0;
- if (targetState == ClimbStates.onPoint)
- {
- ik_L = ik.ReturnOppositeIK(ik_L);
- }
- else
- {
- if (Mathf.Abs(relativeDirection.x) > 0)
- {
- if (relativeDirection.x < 0)
- ik_L = AvatarIKGoal.LeftHand;
- else
- ik_L = AvatarIKGoal.RightHand;
- }
- targetAnim = (ik_L == AvatarIKGoal.RightHand) ? 1 : 0;
- if (relativeDirection.y < 0)
- targetAnim = (ik_L == AvatarIKGoal.RightHand) ? 0 : 1;
- anim.SetFloat("Movement", targetAnim);
- }
- }
- else
- {
- ik_L = (relativeDirection.x < 0) ? AvatarIKGoal.LeftHand : AvatarIKGoal.RightHand;
- if (opposite)
- {
- ik_L = ik.ReturnOppositeIK(ik_L);
- }
- }
- _ikT = 0;
- UpdateIKTarget(0, ik_L, targetPoint);
- ik_F = ik.ReturnOppositeLimb(ik_L);
- _fikT = 0;
- UpdateIKTarget(1, ik_F, targetPoint);
- }
- void InitIK_Direct(Vector3 directionToPoint)
- {
- if (directionToPoint.y != 0)
- {
- _fikT = 0;
- _ikT = 0;
- UpdateIKTarget(0, AvatarIKGoal.LeftHand, targetPoint);
- UpdateIKTarget(1, AvatarIKGoal.LeftFoot, targetPoint);
- UpdateIKTarget(2, AvatarIKGoal.RightHand, targetPoint);
- UpdateIKTarget(3, AvatarIKGoal.RightFoot, targetPoint);
- }
- else
- {
- InitIK(directionToPoint, false);
- InitIKOpposite();
- }
- }
- void InitIKOpposite()
- {
- UpdateIKTarget(2, ik.ReturnOppositeIK(ik_L), targetPoint);
- UpdateIKTarget(3, ik.ReturnOppositeIK(ik_F), targetPoint);
- }
- void UpdateIKTarget(int posIndex, AvatarIKGoal _ikGoal, Point tp)
- {
- _ikStartPos[posIndex] = ik.ReturnCurrentPointPosition(_ikGoal);
- _ikTargetPos[posIndex] = tp.ReturnIK(_ikGoal).target.transform.position;
- ik.UpdatePoint(_ikGoal, tp);
- }
- void HandleWeightAll(float t, AnimationCurve aCurve)
- {
- float inf = aCurve.Evaluate(t);
- ik.AddWeightInfluenceAll(1 - inf);
- //close the ik for the feet if going from hanging to braced
- if (curPoint.pointType == PointType.hanging && targetPoint.pointType == PointType.braced)
- {
- float inf2 = a_zeroToOne.Evaluate(t);
- ik.InfluenceWeight(AvatarIKGoal.LeftFoot, inf2);
- ik.InfluenceWeight(AvatarIKGoal.RightFoot, inf2);
- }
- if(curPoint.pointType == PointType.hanging && targetPoint.pointType == PointType.hanging)
- {
- ik.InfluenceWeight(AvatarIKGoal.LeftFoot, 0);
- ik.InfluenceWeight(AvatarIKGoal.RightFoot, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement