public Quaternion LimitSwing(Quaternion rotation) { if (this.axis == Vector3.zero) { return(rotation); } if (rotation == Quaternion.identity) { return(rotation); } Vector3 vector = rotation * this.axis; float num = RotationLimit.GetOrthogonalAngle(vector, base.secondaryAxis, this.axis); float num2 = Vector3.Dot(vector, base.crossAxis); if (num2 < 0f) { num = 180f + (180f - num); } float maxDegreesDelta = this.spline.Evaluate(num); Quaternion to = Quaternion.FromToRotation(this.axis, vector); Quaternion rotation2 = Quaternion.RotateTowards(Quaternion.identity, to, maxDegreesDelta); Quaternion lhs = Quaternion.FromToRotation(vector, rotation2 * this.axis); return(lhs * rotation); }
protected override Quaternion LimitRotation(Quaternion rotation) { if (this.reachCones.Length == 0) { this.Start(); } return(RotationLimit.LimitTwist(this.LimitSwing(rotation), this.axis, base.secondaryAxis, this.twistLimit)); }
private RotationLimit rotationLimit; // The Rotation Limit component // Aim this part at the target public void AimAt(Transform target) { transform.LookAt(target.position, transform.up); // Finding the Rotation Limit if (rotationLimit == null) { rotationLimit = transform.GetComponent<RotationLimit>(); rotationLimit.Disable(); } // Apply rotation limits rotationLimit.Apply(); }
private Quaternion LimitHinge(Quaternion rotation) { if (this.min == 0f && this.max == 0f && this.useLimits) { return(Quaternion.AngleAxis(0f, this.axis)); } Quaternion quaternion = RotationLimit.Limit1DOF(rotation, this.axis); if (!this.useLimits) { return(quaternion); } Quaternion quaternion2 = quaternion * Quaternion.Inverse(this.lastRotation); float num = Quaternion.Angle(Quaternion.identity, quaternion2); Vector3 vector = new Vector3(this.axis.z, this.axis.x, this.axis.y); Vector3 rhs = Vector3.Cross(vector, this.axis); if (Vector3.Dot(quaternion2 * vector, rhs) > 0f) { num = -num; } this.lastAngle = Mathf.Clamp(this.lastAngle + num, this.min, this.max); return(Quaternion.AngleAxis(this.lastAngle, this.axis)); }
protected override Quaternion LimitRotation(Quaternion rotation) { Quaternion rotation2 = this.LimitSwing(rotation); return(RotationLimit.LimitTwist(rotation2, this.axis, base.secondaryAxis, this.twistLimit)); }
protected override void OnUpdate() { if (this.axis == Vector3.zero) { if (!Warning.logged) { base.LogWarning("IKSolverAim axis is Vector3.zero."); } return; } if (this.poleAxis == Vector3.zero && this.poleWeight > 0f) { if (!Warning.logged) { base.LogWarning("IKSolverAim poleAxis is Vector3.zero."); } return; } if (this.target != null) { this.IKPosition = this.target.position; } if (this.poleTarget != null) { this.polePosition = this.poleTarget.position; } if (this.IKPositionWeight <= 0f) { return; } this.IKPositionWeight = Mathf.Clamp(this.IKPositionWeight, 0f, 1f); if (this.transform != this.lastTransform) { this.transformLimit = this.transform.GetComponent <RotationLimit>(); if (this.transformLimit != null) { this.transformLimit.enabled = false; } this.lastTransform = this.transform; } if (this.transformLimit != null) { this.transformLimit.Apply(); } if (this.transform == null) { if (!Warning.logged) { base.LogWarning("Aim Transform unassigned in Aim IK solver. Please Assign a Transform (lineal descendant to the last bone in the spine) that you want to be aimed at IKPosition"); } return; } this.clampWeight = Mathf.Clamp(this.clampWeight, 0f, 1f); this.clampedIKPosition = this.GetClampedIKPosition(); Vector3 b = this.clampedIKPosition - this.transform.position; b = Vector3.Slerp(this.transformAxis * b.magnitude, b, this.IKPositionWeight); this.clampedIKPosition = this.transform.position + b; for (int i = 0; i < this.maxIterations; i++) { if (i >= 1 && this.tolerance > 0f && this.GetAngle() < this.tolerance) { break; } this.lastLocalDirection = this.localDirection; if (this.OnPreIteration != null) { this.OnPreIteration(i); } this.Solve(); } this.lastLocalDirection = this.localDirection; }
protected override void OnUpdate() { if (axis == Vector3.zero) { if (!Warning.logged) LogWarning("IKSolverAim axis is Vector3.zero."); return; } // Clamping weights if (IKPositionWeight <= 0) return; IKPositionWeight = Mathf.Clamp(IKPositionWeight, 0f, 1f); // Rotation Limit on the Aim Transform if (transform != lastTransform) { transformLimit = transform.GetComponent<RotationLimit>(); if (transformLimit != null) transformLimit.enabled = false; lastTransform = transform; } if (transformLimit != null) transformLimit.Apply(); // In case transform becomes unassigned in runtime if (transform == null) { if (!Warning.logged) LogWarning("Aim Transform unassigned in Aim IK solver. Please Assign a Transform (lineal descendant to the last bone in the spine) that you want to be aimed at IKPosition"); return; } clampWeight = Mathf.Clamp(clampWeight, 0f, 1f); clampedIKPosition = GetClampedIKPosition(); Vector3 dir = clampedIKPosition - transform.position; dir = Vector3.Slerp(transformAxis * dir.magnitude, dir, IKPositionWeight); clampedIKPosition = transform.position + dir; // Iterating the solver for (int i = 0; i < maxIterations; i++) { // Optimizations if (i >= 1 && tolerance > 0 && GetAngle() < tolerance) break; lastLocalDirection = localDirection; Solve(); } lastLocalDirection = localDirection; }
protected override Quaternion LimitRotation(Quaternion rotation) { return RotationLimit.LimitTwist(this.LimitSwing(rotation), this.axis, base.secondaryAxis, this.twistLimit); }