'moving objects input system logic

I'm trying to move my object towards movePoint with the space button through the Input System. The problem I'm having is that the bool I use that is true when I press space is only active for one frame so the distance traveled is very small.

void Update()
    {
        float movementAmount = speed * Time.deltaTime;
        
        bool snaptoHighlight = playerControls.Player.space.WasPerformedThisFrame();

        Debug.Log(snaptoHighlight);

        if (snaptoHighlight)
        {
            //transform.position = movePoint.position;
            transform.position = Vector2.MoveTowards(transform.position, movePoint.position, movementAmount);

        }
    }

If I just use transform.position = movePoint.position the object does move to where I want it to be but it instantly teleports but I am trying to get the moving animation in between the travelling. Is there a way to approach this? thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source