Constraning an object's forces to only two directions in 2D (or infinite friction?)
Hello lovely people,
I want to constrain an object's movement (or the forces that can be applied to it) to two directions. Is that possible? To give you a more precise idea of what I want to do, here is the situation: in the following situation (player is the triangle, and can flip along X and Y axes), I want the player to have to be in the position on the right to continue, as opposed to the position on the left.
In the current situation, (see screengrabs, and code snippet for the movement of the player), if the player just goes up, the collision forces against the diagonal wall pushes it slighlty to the side, allowing it to slide against the wall in any of the above configuration.
void FixedUpdate()
{
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2D.MovePosition (rb2D.position + movement * speed);
}
Things I've tried: Setting the Player's RigidBody2D to "Kinetic". Doesn't work as this ignores the collisions with the "walls". Removing the Player's RigidBody2D and moving it with transform.Translate. Doesn't work as this ignores all collisions, including the triggers. * Setting a material for both the wal and the player object with "1" friction on both. Barely does anything.
Your answer
Follow this Question
Related Questions
How do I assign a velocity to an object on only 1 axis? 1 Answer
Moving Character to mouse click with Rigidbody2D! 0 Answers
A 2D Character Controller with Rigidbody2D.AddForce 2 Answers
Raycast is hitting enemy even when not in contact with it? 2 Answers
Why/How 2d tower of blocks collapse? 0 Answers