Page 1 of 1

[v1]Collision problem

Posted: Fri Feb 14, 2020 11:46 am
by KakCAT
EDIT: Never mind, forget the whole thread. It was a huge mistake on my part (I was using Capsule.Length as substitute to Cylinder.Height, when it's obvious it's not that value). Feel free to delete the thread (I'd have deleted it myself if I could find how to do it :D )

I'm having a problem with Bepu 1. I've modified the CharacterController to use a Capsule instead of a Cylinder to improve movement over bumpy surfaces. It was quite straightforward (actually replacing Cylinder with Capsule is 99% of the job) and works really well... except for a very weird case.

When the modified CharacterController hits a box which is rotated 90º in Z axis the collisions fail, the capsule penetrates the box and you can even climb the box. However it only happens with 1 of the faces of the box! Pushing from all other faces works as it should.

I've uploaded a private video to show the problem:

The first and second box I push in the video are rotated 90º in Z. Second box is scaled ~1.5. Only the most visible face fails, I can push the other faces all I want that there won't be any bug. Third box has no rotation in Z whatsoever. Shows no problems with any face.

I've found that other rotations can also fail, but it's very easy to make it fail with Z=90º. I've also found that the higher the scale of the box the lower the penetration amount is. However you can still climb slowly the box. In very rare cases I haven't been able to determine, the bug encompasses 2 faces of the box, but in most cases the number of faces affected is only one.

All of this doesn't happen with the standard character controller.

There's only one real difference between the Cylinder and Capsule CCs, which is Margin.

I've found out that if you specify a margin to the Capsule, the effective radius of the Capsule is set to the margin value. For this reason I've
commented the line which sets the margin.

I've been playing with different values of margin for the capsule and all of them seem to give the same problem, except values very close to 0.

In any case I'm completely lost with this issue, but I'd really like to stay with the Capsule CC as it works a lot better than the Cylinder one.
Any ideas on what I could try to fix this?


EDIT: Just a note: A simple Capsule entity not attached to the modified CC does not have any of the problems described either. So the problem is probably localized in the CC code.

Re: [v1]Collision problem

Posted: Fri Feb 14, 2020 12:04 pm
by KakCAT
As usual, minutes after you post a big message you start getting progress. I've found that increasing SupportThreshold to a very big value the climbing part almost disappears, however I've yet to check if this has implication in other parts of the game (EDIT: yes, it really takes a toll on the control to increase that value)

However the penetration part problem persists.

Re: [v1]Collision problem

Posted: Fri Feb 14, 2020 8:48 pm
by Norbo

Re: [v1]Collision problem

Posted: Tue Feb 18, 2020 10:11 am
by KakCAT
Hi Norbo! I just realized that what made the CC move nicely was "the buggy part" :lol:

My main problem is stepping up teleporting the character for a very unsmooth movement, just the same problem I had with the cylinder. (I know, this has been documented for 10 years, I'm just that slow). I'll be trying to find a way to keep the "capsule automatic upstepping" but avoid the initial bug, it seems the easiest route.

I just wanted to ask about V2 character controller. I've been having a look at it to try to get ideas on how to do that, and I haven't find any step up/step down code, yet it moves as smooth as my previous CC did. Are you using the capsule bottom of V2 for stepping up (at least for the moment) or there is step up/step down code in the V2 CC but I haven't been able to find it? (I must admit v2 codebase is too cryptic to me :( )

Re: [v1]Collision problem

Posted: Tue Feb 18, 2020 7:01 pm
by Norbo
You can disable teleportation based stepping entirely in v1 by commenting the if here: ... er.cs#L611

Also, if you want to avoid having to modify the CC code, you can keep using the Cylinder shape and just increase its CollisionMargin to the cylinder's Radius. That'll give you a capsule shape because the margin in v1 is 'internal' on cylinders.

If you do both of those things, it'll work similarly to the v2 demo character.

The v2 demo character has no upstepping/downstepping, just the horizontal motion constraints and a capsule shape.

Re: [v1]Collision problem

Posted: Thu Feb 20, 2020 7:17 pm
by KakCAT
thanks for the answer! I disabled the step up/down code and did some changes at IBeforeSolverUpdateable.Update and specially CorrectContacts. The capsule and the margin are not very friendly. I considered going back to the cylinder and try what you said, but I decided to keep the capsule and try to understand what the CC was really doing :lol: (I really stink at physics)

It works quite well now :)