# Calculate the distance for activate a rigidbody

Hi community, I’m currently working on my physics game and in my game, I need to change the character’s movement speed but always keep a rigidbody falling in just front of it. For example:

``````public class Test : MonoBehaviour
{
public Transform cube1;
public Transform cube2;

public float activeDist = 4.0f;
public float speed = 2.0f;

private void Update()
{
cube1.Translate(Vector3.right * Time.deltaTime * speed);
float currentDist = (cube2.position - cube1.position).sqrMagnitude;

if (currentDist < activeDist * activeDist)
{
if (cube2.GetComponent<Rigidbody>().isKinematic)
{
cube2.GetComponent<Rigidbody>().isKinematic = false;
}
}
}
}
``````

I’m not an expert in physics calculation. Let’s say the current movement speed and the active distance works just fine. How can I calculate the activate distance for different movement speed but achieve the same result? And without changing the gravity. Thanks for any help.

Interesting problem
If I get you right, you want blue object fall just before red, if in the range.

I would approach it this way.

• Get vertical distance of blue object.
• Calculate duration of fall, based on gravity.
Knowing the duration
• Calculate velocity of red object
• Calculate distance to travel by red object, within fall duration of blue object.
• Calculate distance from red object to drop point of blue object (in 2D that is just single axis (right))
• Calculate difference between drop point distance and distance to travel withing fall duration.
• You may need add extra offset velocity, to the calculated difference, to ensure blue box falls ahead the red one.
Then
• If difference with offset is 0, drop the blue object.

For first two parts, check out this link with simple equations