OpenTechEngine / Discussions

The issues of this project are abused as a discussion forum for Open Tech
4 stars 0 forks source link

Collisions issue fix #11

Open motorsep opened 9 years ago

motorsep commented 9 years ago

So, finally there is a breakthrough with collisions ( here is the test case https://drive.google.com/open?id=0BwE6dxM0O2PsQUNncWw0aGFuZms ):

http://www.pasteall.org/60504/diff

not mine, but I tested and it works. The only issue that is left is anim stuttering: https://www.youtube.com/watch?v=q-4Z7CTYodk

BielBdeLuna commented 9 years ago

what was the problem originally?

motorsep commented 9 years ago

You would get stuck on the edge. I provided a test case, so you could just try it and see what it does :)

https://www.youtube.com/watch?v=sE_A6awytSE

BielBdeLuna commented 9 years ago

ok, this is for changing slopes? seems pretty interesting!

motorsep commented 9 years ago

I could happen anywhere (I haven't tested flat floors made of models, only terrains, and that piece is a part of the terrain, replicated as brushes)

BielBdeLuna commented 9 years ago

yes, it happens a lot in that map! I had never found a bug like this!, let's add this to the code!

who is the author of the diff?

the stuttering seems to happen anyway with the bug anyway, so solving the bug doesn't introduce the stuttering in the animation.

motorsep commented 9 years ago

"NagaHuntress" is who fixed it.

I have never checked third person view with that bug, so I did know :/ I wonder now how to fix stuttering now.

BielBdeLuna commented 9 years ago

is there a discussion about this somewhere? who is NagaHuntress?

BielBdeLuna commented 9 years ago

in case pasteall deletes it, here is the diff:

Index: cm/CollisionModel_translate.cpp
===================================================================
--- cm/CollisionModel_translate.cpp (revision 6527)
+++ cm/CollisionModel_translate.cpp (working copy)
@@ -294,11 +294,25 @@
            // FIXME: do this normalize when we know the first collision
            tw->trace.c.normal.Normalize();
            tw->trace.c.dist = tw->trace.c.normal * start;
+#if 0
            // make sure the collision plane faces the trace model
            if ( tw->trace.c.normal * trmEdge->start - tw->trace.c.dist < 0.0f ) {
                tw->trace.c.normal = -tw->trace.c.normal;
                tw->trace.c.dist = -tw->trace.c.dist;
            }
+#elif 1
+           // make sure the collision plane faces the direction of the trace
+           if ( tw->trace.c.normal * -tw->dir < 0.0f ) {
+               tw->trace.c.normal = -tw->trace.c.normal;
+               tw->trace.c.dist = -tw->trace.c.dist;
+           }
+#elif 0
+           // make sure the collision plane faces the same way as the polygon plane
+           if ( tw->trace.c.normal * poly->plane.Normal() < 0.0f ) {
+               tw->trace.c.normal = -tw->trace.c.normal;
+               tw->trace.c.dist = -tw->trace.c.dist;
+           }
+#endif
            tw->trace.c.contents = poly->contents;
            tw->trace.c.material = poly->material;
            tw->trace.c.type = CONTACT_EDGE;
BielBdeLuna commented 9 years ago

@motorsep i bet the stuttering is only in the animation script, the model for a moment thinks he is falling or her is not walking (maybe for a single frame) and so he stutters,

when the player is trapped there, he can't jump, maybe he thinks he is falling (you can't jump when not ON_GROUND, and I think it's the only time he can't jump) maybe c++ can't jump but c++ is reporting ON_GROUND anyway, therefore we don't see he is falling and the animation it's not corresponding to the c++ state? maybe this is another error not directly related to the collision error?

the stuttering is not related to IK, because I disabled IK with "ik_enable 0" and the stuttering continues.

DanielGibson commented 9 years ago

You would get stuck on the edge. I provided a test case, so you could just try it and see what it does :)

Yeah right "you" provided a testcase. I recreated the buggy part of your terrain mesh in brushes back then to get this minimal testcase.

Back when we first debugged this issue, treb proposed a patch to do q3 style collision detection there which gave the same results (you don't get stuck anymore on that edge, but it stutters a bit). For some reason you (motorsep) didn't want it.

Unfortunetely I think that fix got lost with doom3world

DanielGibson commented 9 years ago

I just found trebs patch for dhewm3:

--------------------- neo/game/physics/Physics_Player.cpp ---------------------
index af1a764..9ab46a8 100644
@@ -971,6 +971,9 @@ void idPhysics_Player::CheckGround( void ) {
    EvaluateContacts();

    // setup a ground trace from the contacts
+   gameLocal.clip.Translation( groundTrace, current.origin, current.origin +
+                gravityNormal * CONTACT_EPSILON, clipModel, clipModel->GetAxis(), -1, self );
+   /*
    groundTrace.endpos = current.origin;
    groundTrace.endAxis = clipModel->GetAxis();
    if ( contacts.Num() ) {
@@ -983,6 +986,7 @@ void idPhysics_Player::CheckGround( void ) {
    } else {
        groundTrace.fraction = 1.0f;
    }
+   */

    contents = gameLocal.clip.Contents( current.origin, clipModel, clipModel->GetAxis(), -1, self );
    if ( contents & MASK_SOLID ) {
BielBdeLuna commented 9 years ago

which one should we apply?

I'll copy Trebs solution to the issue...

motorsep commented 9 years ago

@DanielGibson Just wow. "I provided" means I posted it here for you, people. You made the test case from the map I made, sure. Sorry if I didn't put copyright note here.

Trebor's fix might be as well as good, but it's for player only. The new fix addresses the issue in the collisions code, meaning it is potentially a fix for NPC and AI (although I never tested them on that ledge).

Btw, I think animation jerking got the fix coming too.

BielBdeLuna commented 9 years ago

Motorsep, is there a forum or some web-page where this is discussed, maybe where NagaHuntress is? where did you get that fix from?