- Home /
Question by
Popolee · Dec 16, 2018 at 04:01 AM ·
2dmovementrigidbody2d2d-physics
Player Bump on map border
I have the following code in UNITY 2D
void FixedUpdate()
{
PerformPlayerMovement();
ClampPlayerMovement();
}
void PerformPlayerMovement()
{
if (velocity == Vector2.zero) return;
_rigidbody2D.MovePosition(_rigidbody2D.position + velocity * TimeManager.instance.fixedDeltaTime);
}
void ClampPlayerMovement()
{
transform.position = new Vector3(Mathf.Clamp(transform.position.x, MapManager.bottomLeftMapLimit.x + MAP_BORDER_OFFSET, MapManager.topRightMapLimit.x - MAP_BORDER_OFFSET),
Mathf.Clamp(transform.position.y, MapManager.bottomLeftMapLimit.y + MAP_BORDER_OFFSET, MapManager.topRightMapLimit.y - MAP_BORDER_OFFSET),
transform.position.z);
}
I first Move the player using Rigidbody, then I clamp is position if he goes outside the map,
The problem is the player is "bumping" on map borders, and it's a bit annoying.
I want to move using rigidbody because I will have ice on the map, and I want to use the physics to make the player slide around.
Is there a way to fix the current problem?
Comment
Your answer
Follow this Question
Related Questions
Unity 2d mobile movement 0 Answers
Make an object that moves relative to the touch more natural 0 Answers
Paper Ball Physics Implementation 0 Answers