// Apply the curve to the specified solver, effector, with the value and weight. private void Apply(IKSolverFullBodyBiped solver, FullBodyBipedEffector effector, WeightCurve.Type type, float value, float weight) { switch (type) { case WeightCurve.Type.PositionWeight: solver.GetEffector(effector).positionWeight = Mathf.Lerp(solver.GetEffector(effector).positionWeight, value, weight); return; case WeightCurve.Type.RotationWeight: solver.GetEffector(effector).rotationWeight = Mathf.Lerp(solver.GetEffector(effector).rotationWeight, value, weight); return; case WeightCurve.Type.PositionOffsetX: solver.GetEffector(effector).position += solver.GetRoot().rotation *Vector3.right *value *weight; return; case WeightCurve.Type.PositionOffsetY: solver.GetEffector(effector).position += solver.GetRoot().rotation *Vector3.up *value *weight; return; case WeightCurve.Type.PositionOffsetZ: solver.GetEffector(effector).position += solver.GetRoot().rotation *Vector3.forward *value *weight; return; case WeightCurve.Type.Pull: solver.GetChain(effector).pull = Mathf.Lerp(solver.GetChain(effector).pull, value, weight); return; case WeightCurve.Type.Reach: solver.GetChain(effector).reach = Mathf.Lerp(solver.GetChain(effector).reach, value, weight); return; } }
// Update the Body public void Update(IKSolverFullBodyBiped solver, float w, float deltaTime) { if (transform == null || relativeTo == null) return; // Find the relative position of the transform Vector3 relativePos = relativeTo.InverseTransformDirection(transform.position - relativeTo.position); // Initiating if (firstUpdate) { lastRelativePos = relativePos; firstUpdate = false; } // Find how much the relative position has changed Vector3 delta = (relativePos - lastRelativePos) / deltaTime; // Smooth the change smoothDelta = speed <= 0f? delta: Vector3.Lerp(smoothDelta, delta, deltaTime * speed); // Convert to world space Vector3 worldDelta = relativeTo.TransformDirection(smoothDelta); // Extract horizontal and vertical offset Vector3 offset = V3Tools.ExtractVertical(worldDelta, solver.GetRoot().up, verticalWeight) + V3Tools.ExtractHorizontal(worldDelta, solver.GetRoot().up, horizontalWeight); // Apply the amplitude to the effector links for (int i = 0; i < effectorLinks.Length; i++) { solver.GetEffector(effectorLinks[i].effector).positionOffset += offset * w * effectorLinks[i].weight; } lastRelativePos = relativePos; }
public void Apply(IKSolverFullBodyBiped solver, float weight) { for (int i = 0; i < this.effectorLinks.Length; i++) { this.effectorLinks[i].Apply(solver, weight, solver.GetRoot().rotation); } }
public void Update(IKSolverFullBodyBiped solver, float w, float deltaTime) { if (this.transform == null || this.relativeTo == null) { return; } Vector3 a = this.relativeTo.InverseTransformDirection(this.transform.position - this.relativeTo.position); if (this.firstUpdate) { this.lastRelativePos = a; this.firstUpdate = false; } Vector3 vector = (a - this.lastRelativePos) / deltaTime; this.smoothDelta = ((this.speed > 0f) ? Vector3.Lerp(this.smoothDelta, vector, deltaTime * this.speed) : vector); Vector3 v = this.relativeTo.TransformDirection(this.smoothDelta); Vector3 a2 = V3Tools.ExtractVertical(v, solver.GetRoot().up, this.verticalWeight) + V3Tools.ExtractHorizontal(v, solver.GetRoot().up, this.horizontalWeight); for (int i = 0; i < this.effectorLinks.Length; i++) { solver.GetEffector(this.effectorLinks[i].effector).positionOffset += a2 * w * this.effectorLinks[i].weight; } this.lastRelativePos = a; }
public void Apply(IKSolverFullBodyBiped solver, float weight, Quaternion rotation) { solver.GetEffector(this.effector).positionOffset += rotation * this.offset * weight; Vector3 vector = solver.GetRoot().position + rotation * this.pin - solver.GetEffector(this.effector).bone.position; Vector3 vector2 = this.pinWeight * Mathf.Abs(weight); solver.GetEffector(this.effector).positionOffset = new Vector3(Mathf.Lerp(solver.GetEffector(this.effector).positionOffset.x, vector.x, vector2.x), Mathf.Lerp(solver.GetEffector(this.effector).positionOffset.y, vector.y, vector2.y), Mathf.Lerp(solver.GetEffector(this.effector).positionOffset.z, vector.z, vector2.z)); }
public Vector3 pinWeight; // Pin weight vector #endregion Fields #region Methods // Apply positionOffset to the effector public void Apply(IKSolverFullBodyBiped solver, float weight) { // Offset solver.GetEffector(effector).positionOffset += solver.GetRoot().rotation * offset * weight; // Calculating pinned position Vector3 pinPosition = solver.GetRoot().position + solver.GetRoot().rotation * pin; Vector3 pinPositionOffset = pinPosition - solver.GetEffector(effector).bone.position; Vector3 pinWeightVector = pinWeight * Mathf.Abs(weight); // Lerping to pinned position solver.GetEffector(effector).positionOffset = new Vector3( Mathf.Lerp(solver.GetEffector(effector).positionOffset.x, pinPositionOffset.x, pinWeightVector.x), Mathf.Lerp(solver.GetEffector(effector).positionOffset.y, pinPositionOffset.y, pinWeightVector.y), Mathf.Lerp(solver.GetEffector(effector).positionOffset.z, pinPositionOffset.z, pinWeightVector.z) ); }
protected override void OnApply(IKSolverFullBodyBiped solver, float weight) { Vector3 a = solver.GetRoot().up *base.force.magnitude; Vector3 vector = this.offsetInForceDirection.Evaluate(base.timer) * base.force + this.offsetInUpDirection.Evaluate(base.timer) * a; vector *= weight; foreach (HitReaction.HitPointEffector.EffectorLink effectorLink in this.effectorLinks) { effectorLink.Apply(solver, vector, base.crossFader); } }
protected override void OnApply(IKSolverFullBodyBiped solver, float weight) { Vector3 a = solver.GetRoot().up *base.force.magnitude; Vector3 vector = this.offsetInForceDirection.Evaluate(base.timer) * base.force + this.offsetInUpDirection.Evaluate(base.timer) * a; vector *= weight; HitReaction.HitPointEffector.EffectorLink[] array = this.effectorLinks; for (int i = 0; i < array.Length; i++) { array[i].Apply(solver, vector, base.crossFader); } }
// Calculate offset, apply to FBBIK effectors protected override void OnApply(IKSolverFullBodyBiped solver, float weight) { Vector3 up = solver.GetRoot().up *force.magnitude; Vector3 offset = (offsetInForceDirection.Evaluate(timer) * force) + (offsetInUpDirection.Evaluate(timer) * up); offset *= weight; foreach (EffectorLink e in effectorLinks) { e.Apply(solver, offset, crossFader); } }
public Vector3 pinWeight; // Pin weight vector // Apply positionOffset to the effector public void Apply(IKSolverFullBodyBiped solver, float weight, Quaternion rotation) { // Offset solver.GetEffector(effector).positionOffset += rotation * offset * weight; // Calculating pinned position Vector3 pinPosition = solver.GetRoot().position + rotation * pin; Vector3 pinPositionOffset = pinPosition - solver.GetEffector(effector).bone.position; Vector3 pinWeightVector = pinWeight * Mathf.Abs(weight); // Lerping to pinned position solver.GetEffector(effector).positionOffset = new Vector3( Mathf.Lerp(solver.GetEffector(effector).positionOffset.x, pinPositionOffset.x, pinWeightVector.x), Mathf.Lerp(solver.GetEffector(effector).positionOffset.y, pinPositionOffset.y, pinWeightVector.y), Mathf.Lerp(solver.GetEffector(effector).positionOffset.z, pinPositionOffset.z, pinWeightVector.z) ); }
// Update the Body public void Update(IKSolverFullBodyBiped solver, float w, float deltaTime) { if (transform == null || relativeTo == null) { return; } // Find the relative position of the transform Vector3 relativePos = relativeTo.InverseTransformDirection(transform.position - relativeTo.position); // Initiating if (firstUpdate) { lastRelativePos = relativePos; firstUpdate = false; } // Find how much the relative position has changed Vector3 delta = (relativePos - lastRelativePos) / deltaTime; // Smooth the change smoothDelta = speed <= 0f? delta: Vector3.Lerp(smoothDelta, delta, deltaTime * speed); // Convert to world space Vector3 worldDelta = relativeTo.TransformDirection(smoothDelta); // Extract horizontal and vertical offset Vector3 offset = V3Tools.ExtractVertical(worldDelta, solver.GetRoot().up, verticalWeight) + V3Tools.ExtractHorizontal(worldDelta, solver.GetRoot().up, horizontalWeight); // Apply the amplitude to the effector links for (int i = 0; i < effectorLinks.Length; i++) { solver.GetEffector(effectorLinks[i].effector).positionOffset += offset * w * effectorLinks[i].weight; } lastRelativePos = relativePos; }
// Apply the curve to the specified solver, effector, with the value and weight. private void Apply(IKSolverFullBodyBiped solver, FullBodyBipedEffector effector, WeightCurve.Type type, float value, float weight) { switch (type) { case WeightCurve.Type.PositionWeight: solver.GetEffector(effector).positionWeight = Mathf.Lerp(solver.GetEffector(effector).positionWeight, value, weight); return; case WeightCurve.Type.RotationWeight: solver.GetEffector(effector).rotationWeight = Mathf.Lerp(solver.GetEffector(effector).rotationWeight, value, weight); return; case WeightCurve.Type.PositionOffsetX: solver.GetEffector(effector).position += (positionOffsetSpace != null? positionOffsetSpace.rotation: solver.GetRoot().rotation) * Vector3.right * value * weight; return; case WeightCurve.Type.PositionOffsetY: solver.GetEffector(effector).position += (positionOffsetSpace != null? positionOffsetSpace.rotation: solver.GetRoot().rotation) * Vector3.up * value * weight; return; case WeightCurve.Type.PositionOffsetZ: solver.GetEffector(effector).position += (positionOffsetSpace != null? positionOffsetSpace.rotation: solver.GetRoot().rotation) * Vector3.forward * value * weight; return; case WeightCurve.Type.Pull: solver.GetChain(effector).pull = Mathf.Lerp(solver.GetChain(effector).pull, value, weight); return; case WeightCurve.Type.Reach: solver.GetChain(effector).reach = Mathf.Lerp(solver.GetChain(effector).reach, value, weight); return; case WeightCurve.Type.Push: solver.GetChain(effector).push = Mathf.Lerp(solver.GetChain(effector).push, value, weight); return; case WeightCurve.Type.PushParent: solver.GetChain(effector).pushParent = Mathf.Lerp(solver.GetChain(effector).pushParent, value, weight); return; case WeightCurve.Type.BendGoalWeight: solver.GetChain(effector).bendConstraint.weight = Mathf.Lerp(solver.GetChain(effector).bendConstraint.weight, value, weight); return; } }
// Apply positionOffsets of all the EffectorLinks public void Apply(IKSolverFullBodyBiped solver, float weight) { for (int i = 0; i < effectorLinks.Length; i++) effectorLinks[i].Apply(solver, weight, solver.GetRoot().rotation); }
// Update and Apply the position offset to the effector public void Update(IKSolverFullBodyBiped solver, Vector3 offsetTarget, float weight) { // Lerping offset to the offset target offset = Vector3.Lerp(offset, offsetTarget * multiplier, Time.deltaTime * speed); // Apply gravity Vector3 g = (solver.GetRoot().up * gravity) * offset.magnitude; // Apply the offset to the effector solver.GetEffector(effector).positionOffset += (offset * weight * this.weight) + (g * weight); }
private void Apply(IKSolverFullBodyBiped solver, FullBodyBipedEffector effector, InteractionObject.WeightCurve.Type type, float value, float weight) { switch (type) { case InteractionObject.WeightCurve.Type.PositionWeight: solver.GetEffector(effector).positionWeight = Mathf.Lerp(solver.GetEffector(effector).positionWeight, value, weight); return; case InteractionObject.WeightCurve.Type.RotationWeight: solver.GetEffector(effector).rotationWeight = Mathf.Lerp(solver.GetEffector(effector).rotationWeight, value, weight); return; case InteractionObject.WeightCurve.Type.PositionOffsetX: solver.GetEffector(effector).position += ((this.positionOffsetSpace != null) ? this.positionOffsetSpace.rotation : solver.GetRoot().rotation) * Vector3.right * value * weight; return; case InteractionObject.WeightCurve.Type.PositionOffsetY: solver.GetEffector(effector).position += ((this.positionOffsetSpace != null) ? this.positionOffsetSpace.rotation : solver.GetRoot().rotation) * Vector3.up * value * weight; return; case InteractionObject.WeightCurve.Type.PositionOffsetZ: solver.GetEffector(effector).position += ((this.positionOffsetSpace != null) ? this.positionOffsetSpace.rotation : solver.GetRoot().rotation) * Vector3.forward * value * weight; return; case InteractionObject.WeightCurve.Type.Pull: solver.GetChain(effector).pull = Mathf.Lerp(solver.GetChain(effector).pull, value, weight); return; case InteractionObject.WeightCurve.Type.Reach: solver.GetChain(effector).reach = Mathf.Lerp(solver.GetChain(effector).reach, value, weight); return; case InteractionObject.WeightCurve.Type.RotateBoneWeight: return; case InteractionObject.WeightCurve.Type.Push: solver.GetChain(effector).push = Mathf.Lerp(solver.GetChain(effector).push, value, weight); return; case InteractionObject.WeightCurve.Type.PushParent: solver.GetChain(effector).pushParent = Mathf.Lerp(solver.GetChain(effector).pushParent, value, weight); return; default: return; } }
// Apply the curve to the specified solver, effector, with the value and weight. private void Apply(IKSolverFullBodyBiped solver, FullBodyBipedEffector effector, WeightCurve.Type type, float value, float weight) { switch(type) { case WeightCurve.Type.PositionWeight: solver.GetEffector(effector).positionWeight = Mathf.Lerp(solver.GetEffector(effector).positionWeight, value, weight); return; case WeightCurve.Type.RotationWeight: solver.GetEffector(effector).rotationWeight = Mathf.Lerp(solver.GetEffector(effector).rotationWeight, value, weight); return; case WeightCurve.Type.PositionOffsetX: solver.GetEffector(effector).position += (positionOffsetSpace != null? positionOffsetSpace.rotation: solver.GetRoot().rotation) * Vector3.right * value * weight; return; case WeightCurve.Type.PositionOffsetY: solver.GetEffector(effector).position += (positionOffsetSpace != null? positionOffsetSpace.rotation: solver.GetRoot().rotation) * Vector3.up * value * weight; return; case WeightCurve.Type.PositionOffsetZ: solver.GetEffector(effector).position += (positionOffsetSpace != null? positionOffsetSpace.rotation: solver.GetRoot().rotation) * Vector3.forward * value * weight; return; case WeightCurve.Type.Pull: solver.GetChain(effector).pull = Mathf.Lerp(solver.GetChain(effector).pull, value, weight); return; case WeightCurve.Type.Reach: solver.GetChain(effector).reach = Mathf.Lerp(solver.GetChain(effector).reach, value, weight); return; case WeightCurve.Type.Push: solver.GetChain(effector).push = Mathf.Lerp(solver.GetChain(effector).push, value, weight); return; case WeightCurve.Type.PushParent: solver.GetChain(effector).pushParent = Mathf.Lerp(solver.GetChain(effector).pushParent, value, weight); return; } }
// Calculate offset, apply to FBBIK effectors protected override void OnApply(IKSolverFullBodyBiped solver, float weight) { Vector3 up = solver.GetRoot().up * force.magnitude; Vector3 offset = (offsetInForceDirection.Evaluate(timer) * force) + (offsetInUpDirection.Evaluate(timer) * up); offset *= weight; foreach (EffectorLink e in effectorLinks) e.Apply(solver, offset, crossFader); }