- Home /
I need help with Vectors, Positions, Rigidbody2d and Lerp. Please help me!
Ok. Let's Explain it:
I'm working with points, mouse positions and lerp.
I have a circle, with a CircleCollider, and a Rigibody2d.
I want to move it using the mousePosition and Lerp, so I have a smooth movement, and it was working ok, so I decided to add walls, so the object collide with them. And OK, it's still working, but I also want to trace a LineRenderer which goes to that circle, so I have to send that info to another script.
At this point, two problems are happening (when one happens, the other doesn't):
Problem 1: The Line goes to a point between the mousePosition and the circle position. Problem 2: The Line doesn't go to that point, but the movement of the Rigidbody is not consistent when it collides with a wall, and the mouse is far from it. (suddenly goes to current position to goalPosition instantly when next to edges (I know that happens due to lerp, when collider let the circle move, lerp is already where it is meant to be))
Here is the code:
if ((pos - mousePos).magnitude > 10) {
moving = true;
rbPos = rb.position;
rbPos = new Vector3 (rbPos.x + (mousePos.x - rbPos.x) * Time.deltaTime * 10, rbPos.y + (mousePos.y - rbPos.y) * Time.deltaTime * 10, 0);
//
} else {
moving = false;
}
//
}
void FixedUpdate ()
{
rb.MovePosition (rbPos);
}
I really would like to record it and attach here, but I can't do it now. If needed, I will try to take some screenshots, or record with my phone. Thanks in advance!