## ContactProcess Callback & NewtonMaterialDisableContact

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

### ContactProcess Callback & NewtonMaterialDisableContact

Hi all,

I'm currently trying to implement Stair climbing for a controller class and I'm having trouble getting NewtonMaterialDisableContact working. Either that or my understanding of what it's supposed to do is flawed

Anyway, I'm implementing stair climbing using a technique that I seem to remember Leadwerks describing some time ago. Basically, when there are material contacts that occur below the max step height I want to adjust the body height to that of the contact and signal newton to ignore the contact. The height adjustment is very simple (NewtonSetMatrix) but seems to work a treat. Unfortunately, despite calling NewtonMatrialDisableContact, Newton still seems to be processing the contact which is messing with the controllers horizontal velocity. Below is a snippet of my ContactProcess Callback

Code: Select all
`   Vector position;   Vector normal;   NewtonMaterialGetContactPositionAndNormal(material, position.vec, normal.vec);   Vector local = position - mPosition;   if (local.z > (height / 2.0f))   {      Vector velocity;      NewtonBodyGetVelocity(mBody, velocity.vec);      Matrix transform;      mOrientation.ToRotationMatrix(transform);      transform(0, 3) = mPosition.x;      transform(1, 3) = mPosition.y;      transform(2, 3) = position.z + (height / 2.0f);      NewtonBodySetMatrix(mBody, transform);      NewtonMaterialDisableContact(material);      return 1;   }`

Am I using Disable Contact correctly? Or have I misunderstood what it does? I'm using v1.53.

Any help/suggestions would be greatly appreciated.

Regards,
bmsq
bmsq

Posts: 14
Joined: Mon May 22, 2006 5:59 am
Location: Australia

### Re: ContactProcess Callback & NewtonMaterialDisableContact

Is this 1.53? Or maybe an early beta? In the current betas, you don't have per-contact callbacks, you get a single callback that has all of the contacts to be iterated over.

Anyways, just return 0 if you want to ignore the contact. Returning 1 says "ok, this is a good contact, use it."
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: ContactProcess Callback & NewtonMaterialDisableContact

I'm using v1.53 not any of the beta versions of v2. I thought that was how it is supposed to work too. Unfortunately, trying the same code with return 0 had the same result. Re-reading the docs, only the BeginContact callback states that the collision will be ignored if you return 0 and there isn't any mention about what should be returned from the ProcessContact callback.

Either way, I've tried several combinations of return codes and NewtonMatrialDisableContact. Any other ideas?
bmsq

Posts: 14
Joined: Mon May 22, 2006 5:59 am
Location: Australia

### Re: ContactProcess Callback & NewtonMaterialDisableContact

Not quite sure what to tell you, that's how it's supposed to work, AFAIK. PM Julio for access to the v2 betas, they're rather stable (if that's what's holding you back). Some interface breaking changes, but once you get over them, everything Just Works the way its supposed to.
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

### Re: ContactProcess Callback & NewtonMaterialDisableContact

Found the problem!

Newton was ignoring all the contacts I wanted it to, I just wasn't getting the results I was expecting. I manually adjust the body height when a collision occurs between 0 and the max step height, the code below ignores these collisions and I was expecting smooth horizontal movement because Newton wouldn't process any of the collisions with the stairs.

What was actually happening was that there were very small collisions (with vertical normals) occurring at the base of the body which seems to affect the horizontal movement. Now I ignore all contact collisions (I can do this because of the way I've setup the compound collision used by the controller) and it now works really smooth and doesn't suffer any visible jitter! YAY for newton (the library, not the man )!

Now to work out a robust way of check if the controller is in the air...

Thanks for the help!
bmsq

Posts: 14
Joined: Mon May 22, 2006 5:59 am
Location: Australia

### Re: ContactProcess Callback & NewtonMaterialDisableContact

Glad you got it working . The easiest way to test for air-borne character is probably with a small ray cast. Put point0 at the character's bottom, and put point1 some very small amount below (like 0.01 units). If you hit anything in this small ray, then your character is standing on something. If not, then he/she is probably air-borne. Note that this uses a single centered ray cast, so sides are unaccounted for - to fix this, you can either use a convex cast (present in the v2 betas only) or just use multiple ray casts.
agi_shi

Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm