Hello,
I’m doing university project, and I have problem with smooth movement. On the image below, the rectangle is player who can move anywhere, and I’m trying to implement a ball that can only be moved inside the circle area, within the boarder of course. I’m moving the ball with gamepad. Note that I can move them both at the same time.
I have tried to do this in many different ways, but none of them doesn’t seem to work the way I want.
Any idea and tips to make it smoother?
Heres current code sample:
if((player.transform.position - transform.position).magnitude > moveRadius)
{
movePoint = Vector3.ClampMagnitude((player.transform.position - transform.position), moveRadius);
rb.MovePosition(player.transform.position - movePoint);
}
else
{
movePoint = new Vector3(transform.position.x + horizontal2 * moveSpeed, transform.position.y, transform.position.z + vertical2 * moveSpeed);
rb.MovePosition(movePoint);
}
Example problem drawing: