I'm encountering an issue with my character collider behavior. I have several elements that are relevant to this issue:

  1. a "character" gameobject (capsule mesh), that is assigned with a kinematic rigidbody. It has a script with these methods:

    • OnCollisionEnter determines if the object has a "walkable" tag and if so, changes a "isGrounded" bool to true
    • OnCollisionExit is the opposite, it determines if the player has stopped colliding with this "walkable" object, and if so, turns the "isGrounded" bool to false
    • a "gravity" method, which applies a gravity force on the character if "isGrounded" is false
  2. a "gravity" trigger collider, surrounding the entire game area. OnCollisionStay, this trigger applies a constant gravitational force upon the colliding character in a specified direction (in this case, the direction is -Y).

  3. a "platform", a rigidbody with all position/rotation values locked. This is what the character object stands on top of, and when the character collides with it, the "isGrounded" value becomes true, and the character stops being affected by gravity.

This method works fine in my scene for multiple platforms. When the player lands on them, the OnCollisionEnter works, and when they are dragged off of them (in editor, no movement implemented yet), the OnCollisionExit works, and they start falling again (until they land and the collision enter triggers).

However, all those platforms which work are all either flat or sloped at a very slight angle. I am testing platforms at steeper angles, and find that at slopes of 30 degrees or higher, the player colliding with them causes both OnCollisionEnter and OnCollisionExit to be called every frame. This causes such a serious performance hit that it has even nearly crashed my computer in one instance (and my computer is able to run VR games, so it is hardly lacking in power!). I do not understand why it happens, as the object is clearly colliding with the slope, and as far as I can see, the object is not continuing to move after the initial collision (or at least the position values are not changing for the object). I thought it might be due to the object's orientation or due to the shape of the collider, but changing these variables did not have an effect on the problem.

enter image description here

It looks like the capsule is also never exactly hitting the ground, rather it is floating slightly above it. When I move the capsule to be inside of the platform, the error stops. The collider is the same size as the mesh, so I don't know why it is "colliding" before actually making contact. Is there something I can do to fix this problem? Reducing the collider size doesn't help either.

Can anyone offer insights as to why this problem is occurring, and tell me how I can fix it? Thank you for reading.

  • 1
    \$\begingroup\$ Can you show us your code for controlling this object, including your gravity method? \$\endgroup\$ – DMGregory Mar 13 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.