Using Move Towards for Moving Instantiated Prefab

I can’t seem to figure out why the instantiated object drops at the characters feet and doesn’t move towards the target position (mouse click)…

(I previously tried using rigidbody velocity but didn’t like the feel/look).

    void Update()
    {
        if(Input.GetMouseButtonDown(0)){
            target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
            //Target(target);
            GameObject arrow = Instantiate(projectile, transform.position, Quaternion.identity);
            arrow.transform.position = Vector3.MoveTowards(transform.position, target, projectileSpeed * Time.deltaTime);
            Destroy(arrow, 5.0f);
        }
    }

Note that when moving rigidbodys, you should be moving the objects transform via the rigidbody. That’s the point of the rigidbody. If you are moving a rigidbody using its transform directly, you are going to have issues where things “look” like they are colliding but they actually aren’t.

This mehod doesn’t continue moving towards a target per-frame, you have to do that yourself per-frame. The documentation with a code example show this.

Your code instantiates a prefab at the current objects transform pose then moves it one step only and that’s it.

You need to continue moving the object per-frame or if you want to use a Rigidbody2D then set its velocity. No idea what you mean by “didn’t like the feel or look” because in the end it’s a mechanism to move so has no visuals. Maybe you mean it didn’t seem smooth but that’s because physics doesn’t necessarily update per-frame but you can simply go to the Rigidbody2D and turn on Interpolation.

Certainly, you should NOT have a Rigidbody2D on this prefab instance if you’re manipulating the Transform; that’s bad.