so pretty much what the title says, it has been answered before but since I use the mouse to move the recommentations dont work on my script
void FixedUpdate ()
{
GetComponent<Rigidbody2D> ().velocity = velocity;
Vector3 mousePosition = Input.mousePosition;
mousePosition.z = +1;
if (Input.GetKey (KeyCode.Mouse0))
{
GetComponent<Rigidbody2D> ().freezeRotation = false;
velocity = (Camera.main.ScreenToWorldPoint(mousePosition) - gameObject.transform.position) * Time.deltaTime * 100f;
if (velocity.x >= MaxSpeed.x)
{
velocity.x = MaxSpeed.x;
}
if (-velocity.x >= MaxSpeed.x)
{
velocity.x = -MaxSpeed.x;
}
if (velocity.y >= MaxSpeed.y)
{
velocity.y = MaxSpeed.y;
}
if (-velocity.y >= MaxSpeed.y)
{
velocity.y = -MaxSpeed.y;
}
}
else
{
GetComponent<Rigidbody2D> ().freezeRotation = true;
velocity.x = 0f;
velocity.y = 0f;
}
}