Moving object a certain distance over time

Hey! I’d like to know the math behind this, I have a series of lines which would require a object to traverse them in a set time (for example 1 second to traverse all lines).

How would I calculate this over FixedUpdate?

How you want this object to transverse this lines?
Have you some image to explain what you want?

speed = distance / time :slight_smile:

Vector3 direction = target.position - transform.position;
float distance = direction.magnitude;
float time = 1.0f;//seconds

void Update()
{
transform.Translate(direction * (Time.deltaTime*(distance/time)));
}

etc.

2 Likes

Thanks! :).

Another question, with this script the objects are moving much faster than 1 second. :confused:

Make sure direction is normalised.

1 Like

Yay that fixed it! Thanks again! :slight_smile:

What does “target” mean?