okidoki, so on line 7 I set my moveDirection to be moveDirection but tilted in the direction of whatever I’m standing on and then on line 13 i set my movement in the y direction to be whatever the velocity of the rigidbody is. I call MovePlayer() in FixedUpdate.
Line 7 is to make slopes work, and line 13 is so that I don’t set my y velocity to 0 every update (Making gravity and jumping work like it should).
The problem I think is that when I am standing still my movement should align with the slope, meaning that it should have a y that is slightly less than 0 if I’m walking down and more than 0 if I’m walking up, but I set it to be zero.
In game if I walk on a slope my moveDirection will initially be straight out in front of me, before turning to the desired direction it should be while on a slope.
How can I make it so that gravity and jumping works as it should, but the moveDirection is pointing in the right direction on slopes.
If I didn’t explain this very well feel free to ask me anything.
private void MovePlayer()
{
Physics.Raycast(transform.position, Vector3.down, out slopeHit, playerHeight * 0.5f + 1.0f);
moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
moveDirection = Vector3.ProjectOnPlane(moveDirection, slopeHit.normal);
Vector3 movement = moveDirection.normalized * moveSpeed;
//This breaks my slopes. It's probably because i am supposed to have a negative y value when going down the slope, but i set it to 0.
movement.y = rb.linearVelocity.y;
rb.linearVelocity = movement;