Trouble making object add force towards mouse position

I am currently making a game where I want an object to jump towards where the mouse was clicked and then keep sliding till further input. I have tried to use rigidbody2d add force with a camera scale to world size with the following code:

if (Input.GetMouseButtonDown(0))
  {
    
      rb2d.AddForce(Vector2.MoveTowards(transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition), dashspeed));
  }

dashspeed is the speed at which the object moves and no matter how high I set it it still moves super slow. Is there a way to fix this other then multiplying the number by a ton?

if (Input.GetMouseButtonDown(0))
{
    rb2d.AddForce((Input.mousePosition-Camera.main.WorldToScreenPoint(transform.position)).normalized*dashspeed,ForceMode2D.Impulse);
}
1 Like

Thank you so much! If you don’t mind me asking, what does .normalized do with positions?

Normalizing the direction vector will reduce it to a length/magnitude of 1. This means that no matter how far away the mouse pointer is the object will always move towards it at the speed determined by dashSpeed. Whereas if you don’t normalize the vector the further away the mouse pointer is the faster the object will move towards it. So it really comes down to preference as which type of movement you prefer.

1 Like

Ok, thank you so much for the help and for the explanation!