I’ve been looking for a script where the player mirrors the mouse movement but doesn’t snap to the mouse position. This is my current script:
private Vector3 mousePosition;
private Rigidbody2D rb;
private Vector2 direction;
private float moveSpeed = 100f;
void Start ()
{
rb = GetComponent<Rigidbody2D>();
}
void Update ()
{
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;
}
Feel free to modify this script or create a new one. Thanks.