So I have this code where it does what I want by moving the player behind the mouse and having a variable speed depending on how far away it is from the cursor, but it jitters a lot. I don't understand how I would fix this annoying problem and smooth it out, since I'm new to C#. There might be another was to do this that I don't know about. I would be very greatful if you could help me understand this, thanks!
void FixedUpdate () {
//Follow the mouse
var pos = Input.mousePosition;
pos = Camera.main.ScreenToWorldPoint(pos);
var dir = pos - transform.position;
rigidbody2D.AddForce(dir * 4);
}
↧