Prefabs not moving straight to target

I’ve got units that I am spawning in and setting objectives for them to move to. Everything is working find with setting the objectives and spawning but when the objects translate, instead of moving straight towards the objects, they move in this kind of wide arc to the target. It looks more like they are following a parabola around to the target rather than heading straight there. They do eventually reach the target but I would rather they go in a straight line. Here is the code:

    public GameObject objective;
    public float speed;
   

 void Update()
    {

        if (Vector3.Distance(objective.transform.position, this.transform.position) > 2f)
        {
            transform.LookAt(objective.transform.position);
            transform.Translate(this.transform.forward * speed * Time.deltaTime);
        }
    }
}

Speed is set to 1f at the moment.
Any idea what may be causing this?

1 Answer

1

Could you try Vector3.MoveTowards() instead of transform.Translate?

That works for my prototype temporarily but I'm still not sure what I get that behavior. I'm using that same script on the bullets they fire and trucks the AI drives around with no issue. Any idea why that might be?

I am not sure, but I think transform.Translate works weird with objects that have a rigidbody