I’m making a 3d platformer, and I have it set up so whatever the player is touching, they jump away from, for a more realistic jumping mechanic. It works lovely, except for when I’m touching two things, its somewhat random which normal it uses to jump away from. If I can find out how many colliders the player is touching, I can then say if we’re touching more than 1 collider, just jump vertically.
I tried using collision.contacts.length, because I thought that would give me the number of contact points the player is currently touching, but it always seems to return a 1, even if it’s touching like 5 things.
Below is my code I was testing, with no luck, maybe someone can point me in the right direction? (I’m using platformNormal in my jump code, which isn’t listed, but it basically just adds a force in the direction of platformNormal.)
void OnCollisionStay(Collision collisionInfo)
{
// finds the normal that you're standing on for proper jumping
Debug.Log(collisionInfo.contacts.ToString());
// if were touching more than one surface
if (collisionInfo.contacts.Length > 0)
{
// jump vertically
platformNormal = Vector3.up;
}
else
{
// if we are only touching one object, then jump away from it
platformNormal = collisionInfo.contacts[0].normal;
}
}