Rigidbody sticks to wall
Hi, im moving my character with ridibody with a very simple script that changes the velocity of the ridigbody using the input axis, but when i move towards a wall and try to move in any perpendicular direction, it wons slide along the walls, this makes the movement very akward it feels like the walls are made from glue, now if instead of a rigidbody i use a character controller it will slide naturally.
Looks at this image for illustration, im moving up and then i should be able to move left if i also press left, but it does not, it will only move left if i stop pressing up, this does not happens with character controller, my question is, how do i reproduce this for the rigidbody? i tried having a physics material with 0 friction, but it did not worked.
In fact the same happens in the Stealth tutorial, here im pressing up and left, but the character wont move
Could you provide the script, as well as some screenshots of the inspector for the character and wall?
I dont think is necessary, its a simple script, i reproduced it in a new empty project, just a rigidbody with some contraints and a simple movement script
public class Player$$anonymous$$ove : $$anonymous$$onoBehaviour
{
Rigidbody playerRigidbody;
Vector3 movementVector;
float movementSpeed = 500f;
void Awake()
{
playerRigidbody = transform.GetComponent<Rigidbody>();
}
void Update()
{
Vector3 inputAxis = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
movementVector = inputAxis * movementSpeed * Time.deltaTime;
}
void FixedUpdate()
{
playerRigidbody.velocity = movementVector;
}
}
The only thing that stands out from what I see that might be causing the problem is that you're setting the velocity of the rigidbody directly. Because the rigidbody is NOT kinematic and IS using gravity, you and the physics engine are both manipulating the velocity, potentially fighting with each other.
You should hand off the management of the rigidbody's velocity completely to the physics engine. You can do this by using rigidbody.AddForce
ins$$anonymous$$d of rigidbody.velocity = movementVector
.