bool ISRFootMove(IKSolverFullBodyBiped solver, Vector3 velocity) { Vector3 moveDir = Util.ProjectOntoPlane(velocity, Vector3.up); // float angle = Vector3.Angle(moveDir, solver.GetRoot().right); // if(angle < m_CampAngle) // return true; // else if(angle > 180 - m_CampAngle) // return false; Vector3 rFootToLFoot = solver.GetEffector(FullBodyBipedEffector.LeftFoot).bone.transform.position - solver.GetEffector(FullBodyBipedEffector.RightFoot).bone.transform.position; return(Vector3.Angle(rFootToLFoot, moveDir) > 90f); }
// Update this body, apply the offset to the effector public void Update(IKSolverFullBodyBiped solver, float weight, float deltaTime) { if (transform == null) { return; } // If first update, set this body to Transform if (firstUpdate) { Reset(); firstUpdate = false; } // Acceleration direction = Vector3.Lerp(direction, ((transform.position - lazyPoint) / deltaTime) * 0.01f, deltaTime * acceleration); // Lazy follow lazyPoint += direction * deltaTime * speed; // Match velocity delta = transform.position - lastPosition; lazyPoint += delta * matchVelocity; // Gravity lazyPoint.y += gravity * deltaTime; // Apply position offset to the effector foreach (EffectorLink effectorLink in effectorLinks) { solver.GetEffector(effectorLink.effector).positionOffset += (lazyPoint - transform.position) * effectorLink.weight * weight; } lastPosition = transform.position; }
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 Update(IKSolverFullBodyBiped solver, float weight, float deltaTime, float velocity) { //Update inertia Vector3 delta = m_FollowTarget.position - m_LazyPoint; Vector3 currentSpeed = delta / deltaTime; Vector3 vecChgange = currentSpeed - m_LastVelocity; float dTime = vecChgange.magnitude / m_InertiaAcc; dTime = Mathf.Min(dTime, deltaTime); m_LastVelocity += vecChgange.normalized * m_InertiaAcc * dTime; // m_LazyPoint += m_LastVelocity * deltaTime; delta = m_FollowTarget.position - m_LazyPoint; // Match velocity m_LazyPoint += delta * m_MachVelocity; delta = m_LazyPoint - m_FollowTarget.position; foreach (EffectorLink effectorLink in m_EffectorLink) { solver.GetEffector(effectorLink.m_Effector).positionOffset += delta * effectorLink.m_Weight * weight * m_VelocityFacter.Evaluate(velocity); } }
// Update this body, apply the offset to the effector public void Update(IKSolverFullBodyBiped solver, float weight) { // If first update, set this body to Transform if (firstUpdate) { Reset(); firstUpdate = false; } // not using Time.deltaTime or Time.fixedDeltaTime here, because we don't know if animatePhysics is true or not on the character, so we have to keep track of time ourselves. float deltaTime = Time.time - lastTime; // Acceleration direction = Vector3.Lerp(direction, transform.position - lazyPoint, deltaTime * acceleration); // Lazy follow lazyPoint += direction * deltaTime * speed; // Match velocity delta = transform.position - lastPosition; lazyPoint += delta * matchVelocity; // Gravity lazyPoint.y += gravity * deltaTime; // Apply position offset to the effector foreach (EffectorLink effectorLink in effectorLinks) { solver.GetEffector(effectorLink.effector).positionOffset += (lazyPoint - transform.position) * effectorLink.weight * weight; } lastPosition = transform.position; lastTime = Time.time; }
// Apply offset to FBBIK effectors public void Apply(IKSolverFullBodyBiped solver, Quaternion rotation, float masterWeight) { foreach (EffectorLink e in effectorLinks) { solver.GetEffector(e.effector).positionOffset += rotation * (offset * masterWeight * e.weight); } }
public void Apply(IKSolverFullBodyBiped solver, Quaternion rotation, float masterWeight) { Recoil.RecoilOffset.EffectorLink[] array = this.effectorLinks; for (int i = 0; i < array.Length; i++) { Recoil.RecoilOffset.EffectorLink effectorLink = array[i]; solver.GetEffector(effectorLink.effector).positionOffset += rotation * (this.offset * masterWeight * effectorLink.weight); } }
public bool m_PinWordPos = false; // Wether pin effect in world position public void OnModifyOffset(IKSolverFullBodyBiped solver, Vector3 dir, float timeP, float weight, Vector3 deltaDir) { if (null == solver) { return; } solver.GetEffector(m_Effector).positionOffset += (m_ForceDir.Evaluate(timeP) * dir + m_UpDir.Evaluate(timeP) * Vector3.up - (m_PinWordPos?deltaDir:Vector3.zero)) * weight; }
// Apply offset to FBBIK effectors public void Apply(IKSolverFullBodyBiped solver, Quaternion rotation, float masterWeight, float length, float timeLeft) { additiveOffset = Vector3.Lerp(Vector3.zero, additiveOffset, timeLeft / length); lastOffset = (rotation * (offset * masterWeight)) + (rotation * additiveOffset); foreach (EffectorLink e in effectorLinks) { solver.GetEffector(e.effector).positionOffset += lastOffset * e.weight; } }
// 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); }
public void Apply(IKSolverFullBodyBiped solver, float m_Weight, Vector3 curentVelocity, float deltaTime) { //Update forward tilt Vector3 forwardPro = Vector3.Project(curentVelocity, solver.GetRoot().forward); float curProVelocity = forwardPro.magnitude; if (Vector3.Angle(forwardPro, solver.GetRoot().forward) > 150) { curProVelocity *= -1; } m_ProVelocity = Mathf.Lerp(m_ProVelocity, curProVelocity, m_TileAcc * deltaTime); //Apply offset solver.GetEffector(m_Effector).positionOffset += solver.GetRoot().TransformDirection(m_Offset * m_TileWeight.Evaluate(m_ProVelocity)) * m_Weight; }
// Set effector position and rotation to match it's bone public void SetToBone(IKSolverFullBodyBiped solver, Mode mode) { e = solver.GetEffector(effector); // Using world space position and rotation here for the sake of simplicity of the demo // Ideally we should use position and rotation relative to character's root, so we could move around while doing this. switch (mode) { case Mode.Position: e.position = e.bone.position; e.rotation = e.bone.rotation; return; case Mode.PositionOffset: position = e.bone.position; rotation = e.bone.rotation; return; } }
public Leg(IKSolverFullBodyBiped solver, PuppetMaster puppetMaster, FullBodyBipedEffector effectorType) { this.solver = solver; effector = solver.GetEffector(effectorType); chain = solver.GetChain(effectorType); stepFrom = effector.bone.position; stepTo = effector.bone.position; position = effector.bone.position; offset = effectorType == FullBodyBipedEffector.LeftFoot? Vector3.left: Vector3.right; stepTimer = 0f; stepLength = 0f; muscle = puppetMaster.GetMuscle(effector.bone); thighMuscle = puppetMaster.GetMuscle(chain.nodes[0].transform); mass = muscle.rigidbody.mass; inertiaTensor = muscle.rigidbody.inertiaTensor; }
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 this body, apply the offset to the effector public void Update(IKSolverFullBodyBiped solver, float weight, float deltaTime) { if (transform == null) { return; } // If first update, set this body to Transform if (firstUpdate) { Reset(); firstUpdate = false; } delta = transform.position - lazyPoint; Vector3 currentSpeed = delta / deltaTime; Vector3 vecChgange = currentSpeed - direction; float dTime = vecChgange.magnitude / acceleration; dTime = Mathf.Min(dTime, deltaTime); direction += vecChgange.normalized * acceleration * dTime; lazyPoint += direction * deltaTime; // Match velocity // lazyPoint += delta * matchVelocity.Evaluate(direction.magnitude); lazyPoint += delta * matchVelocity; // Apply position offset to the effector foreach (EffectorLink effectorLink in effectorLinks) { solver.GetEffector(effectorLink.effector).positionOffset += (lazyPoint - transform.position) * effectorLink.weight * weight; } //lastPosition = transform.position; }
// 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 Update(IKSolverFullBodyBiped solver, float weight, float deltaTime) { if (this.transform == null) { return; } if (this.firstUpdate) { this.Reset(); this.firstUpdate = false; } this.direction = Vector3.Lerp(this.direction, (this.transform.position - this.lazyPoint) / deltaTime * 0.01f, deltaTime * this.acceleration); this.lazyPoint += this.direction * deltaTime * this.speed; this.delta = this.transform.position - this.lastPosition; this.lazyPoint += this.delta * this.matchVelocity; this.lazyPoint.y = this.lazyPoint.y + this.gravity * deltaTime; Inertia.Body.EffectorLink[] array = this.effectorLinks; for (int i = 0; i < array.Length; i++) { Inertia.Body.EffectorLink effectorLink = array[i]; solver.GetEffector(effectorLink.effector).positionOffset += (this.lazyPoint - this.transform.position) * effectorLink.weight * weight; } this.lastPosition = this.transform.position; }
// Apply an offset to this effector public void Apply(IKSolverFullBodyBiped solver, Vector3 offset, float crossFader) { current = Vector3.Lerp(lastValue, offset * weight, crossFader); solver.GetEffector(effector).positionOffset += current; }
public void SetToBone(IKSolverFullBodyBiped solver) { solver.GetEffector(this.effector).position = solver.GetEffector(this.effector).bone.position; solver.GetEffector(this.effector).rotation = solver.GetEffector(this.effector).bone.rotation; }
// Set effector position and rotation weight to match the value, multiply with the weight of this Absorber public void SetEffectorWeights(IKSolverFullBodyBiped solver, float w) { solver.GetEffector(effector).positionWeight = w * weight; solver.GetEffector(effector).rotationWeight = w * weight; }