How would I add more force to object A, the closer it is to Object B?
1 Answer
1You’re looking for an inverse relationship.
Here’s a simple linear example:
//y = mx + b
var forceMultiplier = Mathf.Max( 0f, MAX_FORCE - FALLOFF_RATE * Vector3.Distance(posA, posB);
And a simple quadratic example:
//y = 1/x
var forceMultiplier = Mathf.Min( MAX_FORCE, MAX_FORCE / Vector3.Distance(posA,posB);
You’ll want to tweak those until they work for you, of course, but that’s the basic idea.