[SOLVED] Making an object move towards and past a point.

I am trying to make an object move towards and past a point.
This is my script as of now, but the object stops upon reaching the point.

        void Update ()
        {
                transform.position += ((Vector3)targetPos - transform.position).normalized * speed * Time.deltaTime;
        }

It stops because as soon as you pass it, the calculated direction is the opposite. So you’d move back into the direction where you came from until you pass it again, then move forward again, back again etc.

You shouldn’t recalculate the direction this way. If your target doesn’t move, calculate it once and save it somewhere and keep your object move into that direction.

3 Likes

Thanks. That solved it.

1 Like