Hi,
I recently started experimenting with Unity but I ran into some problems with moving my character around with the mouse. I can move my character just fine by holding down left click, but the closer my mouse cursor is to my player object, the slower it moves. I want my object to move at the set movement speed at all times but I cant figure out how to achieve this.
Could someone help me on the right track?
Thanks!
private Vector3 mousePosition;
private Rigidbody2D rb;
private Vector2 direction;
public float moveSpeed = 100f;
if (Input.GetMouseButton(0))
{
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
direction = (mousePosition - transform.position).normalized;
rb.velocity = new Vector2(direction.x * moveSpeed, direction.y* moveSpeed);
}
else
{
rb.velocity = Vector2.zero;
}