I am trying to make my character move up small steps in my game, I have seen people using invisible sloped colliders to simulate a ramp but this is not effective in my game as there are many small segments in which my character can walk over, such as a small fence, or pieces on a bent roped bridge.
When using the character controller, there is a slope limit that allows the character to walk over small objects, I would like to achieve a similar effect with rigidbodies. I am using the following code but in my test picture below, there is no slope on the objects so it never returns true.
#EDIT
So i’ve managed a workaround which uses 2 raycasts, one at the base of my characters feet and one just above it, I only run the code if the one at the feet touches an object, this works for standard cubes and spheres from unity, but it will not work on my imported models, any ideas why?
#EDIT 2
After playing around with it some more this morning, it seems that the code below works but only if the object in question (3 cubes below) are passing through the terrain slightly, that is, if they are colliding with another object, so if i get all my objects and lower them slightly into the ground, my code works, but not if they are sitting on the terrain. I am very stumped at this and would appreciate any ideas.
void CheckForSteps()
{
RaycastHit hit;
RaycastHit headHit;
Debug.DrawRay(transform.position, transform.forward, Color.red, 1.0f);
Debug.DrawRay(transform.position + new Vector3(0,0.4f, 0), transform.forward, Color.red, 1.0f);
if (Physics.Raycast(transform.position, transform.forward, out hit, 1.0f) && !Physics.Raycast(transform.position + new Vector3(0,0.4f, 0), transform.forward, out headHit, 1.0f))
{
Debug.Log("Hitting");
if (Vector3.Dot(Vector3.up, hit.normal) < 0.7f)
{
caecusRigidbody.GetComponent<Rigidbody>().AddForce(transform.up, ForceMode.VelocityChange);
}
}
}