Hello, I’m new to this and was wondering how I could reset my moveSpeed to its original value after reaching the cursor. For example the sprite follows the cursor at .1 speed then speeds up to .5 when I click but then slows down to .1 after reaching the cursor.
using UnityEngine;
public class MouseFollow : MonoBehaviour
{
Vector3 mousePosition;
public float moveSpeed = 0.1f;
Rigidbody2D rb;
Vector2 position = new Vector2(0f, 0f);
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos.z = 10f;
if(Input.GetMouseButtonDown(0))
{
moveSpeed = .5f;
}
}
private void FixedUpdate()
{
rb.MovePosition(position);
}
}