public override void PhysicsUpdate(Vector3 toTarget, PhysicsTest physicsObject) { float sqrDistance = toTarget.sqrMagnitude; //if(sqrDistance < distanceToCheckSquared) //{ // float ratio = Mathf.Sqrt(sqrDistance / distanceToCheckSquared); // usedStrength = strength * strengthBasedOnNearDistance.Evaluate(ratio); //} if (sqrDistance > arrivedDistanceSquared) { float usedStrength = strength; if (Mathf.Sign(Vector3.Dot(toTarget, physicsObject.Rigid.velocity)) > 0) { float stopDistance = physicsObject.Rigid.velocity.sqrMagnitude / (2 * strength); if (sqrDistance < stopDistance * stopDistance) { usedStrength = -strength; } } toTarget /= Mathf.Sqrt(sqrDistance); physicsObject.ApplyForce(toTarget * usedStrength); } }
public override void PhysicsUpdate(Vector3 toTarget, PhysicsTest physicsObject) { Vector3 tgtVel = toTarget * toVel; if (toTarget.sqrMagnitude * toVel * toVel > maxVelSquared) { Debug.Log("Clamping"); tgtVel = toTarget.normalized * Mathf.Sqrt(maxVelSquared); } Vector3 error = tgtVel - physicsObject.Rigid.velocity; Vector3 force = Vector3.ClampMagnitude(gain * error, maxForce); physicsObject.ApplyForce(force); }
public override void PhysicsUpdate(Vector3 toTarget, PhysicsTest physicsObject) { Vector3 tgtVel = toTarget * toVel; if (toTarget.sqrMagnitude * toVel * toVel > maxVelSquared) { tgtVel = toTarget.normalized * Mathf.Sqrt(maxVelSquared); } Vector3 error = tgtVel - physicsObject.Rigid.velocity; float maxForce = this.maxForce * strengthBasedOnVelocity.Evaluate(physicsObject.Rigid.velocity.magnitude) * distanceToStrength.Evaluate(toTarget.magnitude); maxForce = Mathf.Lerp(this.maxForce, maxForce, massToLerp.Evaluate(physicsObject.Rigid.mass)); Vector3 force = Vector3.ClampMagnitude(gain * error, maxForce); force -= physicsObject.Rigid.velocity * physicsObject.Rigid.mass * dampeningFactor; physicsObject.ApplyForce(force); }