1
votes

I have a game in which I want my player to jump from one platform to the other. On my platform I have a box collider.

When I tried to jump, sometimes my player would hit the side of the collider and start grinding up against it and would slip down and finally trigger the death condition. To prevent this, I put a trigger collider next to my platform. I also put the trigger collider slightly below the box collider so that in case my player jumps on the edge, he doesn't activate both.

If the trigger activates, I play the death function, otherwise I assume the player has made a solid jump and go on with the other game logic. However, I notice that sometimes when the player lands on the edge of the platform it enters the on collision function as well as the on trigger event.

This is strange because I notice in my scene view that the player collider has not entered the trigger collider below the platform.

I have tried adding raycast to the mix but I'm still getting this bug, and even despite the raycasts I don't understand why OnTriggerEnter is triggering when the player hasn't entered the trigger.

I did consider the fact that the player collider might push into the platform collider since the player is falling with some speed but I thought it would show up in the scene view.

picture with the mesh and colliders

picture with collider orientation only

My question is, when I land on the platform collider how is it possible for the trigger collider to trigger? I'm jumping on top of it, not from below it. If I miss the platform completely the trigger fires as expected but on occasions it will land on top of the platform have no overlap with the trigger collider and still fire it.

/e

sketch

this is a side on view of my 3d environment. It is not the exact depiction but to simplify it for you guys. My player is jumping from one platform to the other, both of these platforms are for all means and purposes 3d cubes with box colliders. In between the two platforms but at a slightly lower level I have a trigger collider.

when my player hits the trigger collider its game over. my question is sometimes my player will land on the edge of the box collider as in the sketch but for some reason it will trigger the gameover trigger collider when there is no penetration of my player collider with the trigger collider, as you can see there is plenty of space in between them they arent even touching.

To sum up - my ontriggerenter is running when there is no visible contact between my player and the trigger collider, question is why?

actual game screenshot

ignore the draw ray, as you can see, my player collider is firmly on top of the platform box collider, and yet ontriggerenter for the collider next to and below the platform is triggered and my player goes into death animation. I cant be more specific then this, its up to you guys to help me out now and explain why this is happening. my player is far away from the triggercollider they arent touching.

1
Please edit your question with your code and separate it to make it more readable.Programmer
This isnt exactly related to the code, ill put some screen shots to make more sense though so you can see the collidersHasan Nagaria
i see more than 2 platform, 1 inside the other, and 1 is have very low height. You need to simplify ever box colliders. The precision needed for a big resolution is very expensive in resources and sure you not set this correctly. Better try to get bigger boxs and with suficient distances, and no 1 inside anotherjoreldraw
One thought: rather than playing the animation based on which trigger volume is activated, instead play the animation based on which collider the player hits. That is: remove the logic from the platform and instead perform the operation from the player side. That way you can discriminate correctly when both triggers are within range.Draco18s no longer trusts SE
@Draco18s Can you elaborate what that means? At the moment I am performing the operation on the player side, in my player script i am checking in oncollisionenter when i hit the collider and ontriggerenter i am checking when i am entering a trigger.Hasan Nagaria

1 Answers

1
votes

As always, no response from Stackoverflow.

Anyways I was able to find a solution to my problem. The solution was ugly and its not worth sharing but for anyone else stuck with collision detection and such the following things or a combination of the following might help you find a solution.

1 - You can consider changing the rigidbodies colliding between each other to continuous or continuous dynamic. This will increase performance overhead but will lead to much better collision between the rigidbodies.

2 - In settings, physics manager you can try to turn up the Default Solver Iterations. From the documentation: Solvers are small physics engine tasks which determine a number of physics interactions, such as the movements of joints or managing contact between overlapping Rigidbody components. Use Default Solver Iterations to define how many solver processes Unity runs on every physics frame. This affects the quality of the solver output and it’s advisable to change the property in case non-default Time.fixedDeltaTime is used, or the configuration is extra demanding. Typically, it’s used to reduce the jitter resulting from joints or contacts.

These or a combination of these might be something to look at.