I followed this tutorial to make so that my character in my FPS game can go up stairs using Rigidbody instead of CharacterController due to it’s limitations (namely not being able to change the shape of it’s collider), and uh… It didn’t work :p.
I made another thread earlier trying to make so the player can go up stairs in all directions:
I modified the video’s solution by using a Physics.CheckBox instead of Physics.Raycast, but it just… Didn’t work. The raycast solution wasn’t working properly either.
Basically, no matter what value I put for the size of the check box, it is very glitchy and can’t really detect well the stairs, even if they are right in front of the player. I checked the code and couldn’t find any issues with it, and indeed when I make the box insanely long it does detect the stairs from afar (the player sort of keeps bumping upwards), it just can’t make the player properly climb them. I was able to go through one of the stairs I used to test in a very specific direction though.
I don’t know what the issue is so I will just put the code here and say what I know is not the issue because I tested:
[Header("Steps and slopes")]
public Transform StepCheckHigher; //If the step is taller than this object, it should not be climbed automatically//
public Transform StepCheckLower; //Checks for obstacles//
public Vector3 StepCheckHigherSize; //How far the lower step ray checks for an obstacle//
public Vector3 StepCheckLowerSize; //How far the lower step ray checks for an obstacle//
public float StepHeight = 0.4f; //How tall an obstacle can be so the player can step up automatically//
public float StepAmount = 0.1f; //How much the player climbs up steps//
Inside of void Start():
StepCheckHigher.position = new Vector3(StepCheckLower.position.x, StepCheckLower.position.y + StepHeight, StepCheckLower.position.z);
Inside of void FixedUpdate():
if (Player.PlayerMovementStatus != PlayerStats.PlayerState.Standing)
{
StepClimb();
}
void StepClimb()
{
if (Physics.CheckBox(StepCheckLower.position, StepCheckLowerSize, StepCheckLower.rotation, SolidLayer))
{
if (!Physics.CheckBox(StepCheckHigher.position, StepCheckHigherSize, StepCheckHigher.rotation, SolidLayer))
{
PlayerRigidbody.position += new Vector3(0f, StepAmount * Time.deltaTime, 0f);
}
}
}
- It can’t be due to the
ifinside ofvoid FixedUpdate()checking if the player is standing or not because it glitches out even while the player is clearly moving; - It can’t be due to the size of the check box, because even with different sizes the same issue appears;
- It can’t be due to the player’s own collider interacting with the check box because the player moves just fine around outside of stairs;
- It can’t be due to the
StepAmountvalue being too low, because I already tested with different values and it still doesn’t work properly; - It can’t be due to the stairs themselves because I tested stairs of different sizes and shapes and they all have the same issue;
So how do I fix that?