Body setup problems

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Body setup problems

Postby aitzolmuelas » Fri May 29, 2015 11:11 am

I am having several problems setting up the properties of the bodies in a game. There are different types of bodies, and I am no longer certain of how to properly set them up to get them all to do what I expect (I have tried maaany variations).
The 'behaviours' that I need are as follows (I include what I do to set them up and what I expect) [in the provided code, 'world', 'collision' and 'location' refer to a properly initialized NewtonWorld, a properly initialized NewtonCollision and the location matrix for that body]:


- Type A: triggers
+ Desired Behaviour: do not interact physically at all with other bodies, but generate contact joints for CustomTriggerManager (I even need to get NewtonContactJointGetClosestDistance() to control how the automatic cameras in the game are interpolated). These triggers may be static or move around controlled by entities or scripts.
+ Setup:
Code: Select all
  NewtonCollisionSetMode( collision, 0 );
  body = NewtonCreateKinematicBody( world, collision, location );
 



- Type B: static geometry
+ Desired Behaviour: affect dynamic bodies in the solver, but are not affected by them (mostly scenario. I tried to put them all in the scene collision, but they have different setups for broadphase filtering and ended up being too cumbersome, so I keep them as separate bodies).
+ Setup:
Code: Select all
  body = NewtonCreateKinematicBody( world, collision, location );
  NewtonBodySetCollidable( body, 1 );
 



- Type C: kinematic bodies (in the traditional sense)
+ Desired Behaviour: same behaviour as Type B (statics) but can be moved around by scripts (like moving platforms).
+ Setup:
Code: Select all
  body = NewtonCreateKinematicBody( world, collision, location );
  NewtonBodySetMassProperties( body, 1.0f * NewtonConvexCollisionCalculateVolume( collision ), collision );
  NewtonBodySetCollidable( body, 1 );
 

*Note that I have had to give them mass (it seems bizarre to me) otherwise they do not activate triggers.


- Type D: characters
+ Desired Behaviour: a 'mockup' for characters, as I am currently still working on the CustomCharacterController for our game (however, the mockup does the job for now). They should collide physically with Types B and C, and also activate triggers.
+ Setup:
Code: Select all
  body = NewtonCreateDynamicBody( world, collision, location );
  NewtonBodySetMassProperties( body, 1.0f * NewtonConvexCollisionCalculateVolume( collision ), collision );
  NewtonBodySetForceAndTorqueCallback( body, characterForceCallback );
  NewtonConstraintCreateUpVector( world, Vector(0, 1, 0), body );
  NewtonBodySetContinuousCollisionMode( body, 1 );
  NewtonBodySetTransformCallback( body, setTransformCallback );
 



Type D has several tweaks of its velocity and acceleration in the respective callback. As I mentioned, I intend to improve its physical behaviour in a Custom Controller, but it does the job for now.

The main problem is that, even having tweaked the setup in weird ways to get it to work as much as possible (giving mass to Type C???), I cannot get moving triggers (Type A) to detect static geometry (Type B).
I have tried many possibilities for setup, this is simply the one that gets most stuff to work (but not all). Am I missing something or doing something wrong? What is the proper way to setup the bodies for the behaviour I described? Thanks
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Body setup problems

Postby Julio Jerez » Fri May 29, 2015 1:26 pm

let us take one case at time.
let us go with type A first, are yo using the Trigger manager?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby JoeJ » Fri May 29, 2015 1:45 pm

http://newtondynamics.com/forum/viewtopic.php?f=9&t=8139&p=55124&hilit=moving+platforms#p55124
This thread answers why kinematic bodies have mass.

For static geometry (B) the usual way is to use dynamic bodies, but with zero mass.

Examples where i would use kinematic bodies are:
Conveyor belt (simply set a velocity, they won't move, but dynamic bodies on top of them will)
Elevators and other moving platforms
Other stuff that has to follow fixed animation
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Body setup problems

Postby aitzolmuelas » Tue Jun 02, 2015 6:33 am

Ok, i finally got to trying the suggestions by JoeJ today and made my static bodies 'massless dynamic', and I still cannot get everything to work properly. The main problem is that triggers do NOT generate contact joints when colliding with massless bodies (you can test this in the Advanced Character demo by commenting line 101 in CustomPlayerControllerManager.cpp, where mass is set: character will no longer activate triggers and platforms cannot be activated).
I have tried giving mass to all statics, but first of all it seems just wrong and second, it runs A LOT slower. Also something behaves weirdly in one of the scenarios, with the player being pushed around and flying away randomly, and after a short time it invariably ends up crashing due to the same bug reported here

viewtopic.php?f=12&t=8809
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Body setup problems

Postby Julio Jerez » Tue Jun 02, 2015 8:41 am

trigger are no support to interact with mass less objects.
what are you doing?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby aitzolmuelas » Tue Jun 02, 2015 10:06 am

For instance, there are several traps and/or enemies in the game which throw bombs or projectiles at you (slow moving, so they can be dodged). All their logic is implemented based on triggers: the projectiles themselves are triggers which launch a script when colliding with things (the script determines what to do based on what type of thing it collided against). They must be able to collide against most of the static geometry in the scene.
Out of curiosity, how come triggers cannot collide with static bodies? I don't see how triggers and mass are related. Also, would there be any other clean way to achieve this (maybe having more custom stuff in a derived trigger manager of my own?)
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Body setup problems

Postby Julio Jerez » Tue Jun 02, 2015 10:36 am

aitzolmuelas wrote:For instance, there are several traps and/or enemies in the game which throw bombs or projectiles at you (slow moving, so they can be dodged). All their logic is implemented based on triggers: the projectiles themselves are triggers which launch a script when colliding with things (the script determines what to do based on what type of thing it collided against). They must be able to collide against most of the static geometry in the scene.

that's the problem you want to make the projectile a trigger and trigger do not interact with triggers.
you need top make your projectile a Kinematic collidable body.
That is what the player controller is and the collide with triggers.

aitzolmuelas wrote:Out of curiosity, how come triggers cannot collide with static bodies? I don't see how triggers and mass are related. Also, would there be any other clean way to achieve this (maybe having more custom stuff in a derived trigger manager of my own?)

Ok here are tow definitions that may help you.
In Newton you have Dynamics and Kinematics bodies

a dynamics body is one that get physic force and integration. if a dynamics body has infinity mass
which in newton is denoted by setting the mass to zero, in become a static body.
By design static body do no collide with static bodies.

a Kinematic body is one that do not get physics forces. the client application have to integrate them.
kinematic bodies also can have mass and if they face infinite mass the ate static kinematic.
Kinematic can be collidable or non collidable.
a trigger is a non collidable kinematic body

the interaction are:
dynamic with mass interact with every thing
Kinematic collidable interact with every thing.
dynamic with zero mass interact with dynamic with mass and Kinematic collidable

the only interaction that are no allowed are
kinematic non collidable with kinematic non collidable
kinematic non collidable with dynamic with zero mass
dynamic with zero mass with dynamic with zero mass

fi you make you projectile a kinematic collidable with mass, the is will interact with trigger.
In general you do no want to make game player object triggers. triggers are just region of space tat you can use as variable in the scene.


and finally yes you can make you own mangers.
a trigger is just a non collidable kinematic body. It has to be otherwise it will prevent other object form penetration it. They are only one way interaction.
the trigger manager in the custom only do the housekeeping of sending event with some body is inside outside the trigger. by that body can not be other trigger or a static body.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby Julio Jerez » Tue Jun 02, 2015 10:45 am

How many bodies in the scene are we talking about?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby aitzolmuelas » Tue Jun 02, 2015 12:22 pm

that's the problem you want to make the projectile a trigger and trigger do not interact with triggers.

No, i may not have explained properly: the projectiles are the triggers, and I need them to collide with static geometry.
Kinematic collidable interact with every thing.

Right now I am testing the scene/static geometry as kinematic-collidable, and triggers (kinematic non-collidable) do not interact with the former unless the triggers do not move, even if I give mass to the static/scene geometry. The same happens if I implement static geometry as dynamic-zero-mass. Is there a problem with moving triggers?
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Body setup problems

Postby Julio Jerez » Tue Jun 02, 2015 1:10 pm

aitzolmuelas wrote:
that's the problem you want to make the projectile a trigger and trigger do not interact with triggers.

newton by design newton does no support collision between triggers and static objects.
for a projectile to generate contacts you have to make kinematic object with collision.
The will generate contacts but it will no act on them.

sorry that newton does not supports that. this will be extremely hard to add because the concept of mass lest (infinite mass) no collidable by definition is the cornerstone action of the newton core.

I do no understand why you can not make the way I tell you. I have being doing this for many years and those options more than satisfy the needs of any Project I ever worked.

Right now I am testing the scene/static geometry as kinematic-collidable, and triggers (kinematic non-collidable) ..

this too is a mistake in the design. The scene should be static, then you place triggers in the ares you need events, this is why trigger do no generate contacts with kinematic. And yes triggers can move.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby aitzolmuelas » Tue Jun 02, 2015 1:33 pm

Julio Jerez wrote:for a projectile to generate contacts you have to make kinematic object with collision.

You mean NewtonBodySetCollidable? I cannot do that as many triggers, like sight sensors must not collide (right now I do not have a way to distinguish between the 'different types' of triggers, as they are all the same in our in-house engine). If you mean NewtonCollisionSetMode, I already tried that and it doesn't seem to change anything.
In the general case, what if I need to have a non-solid trigger (a viewing volume, for example) generate contacts with static/scene geometry? Am I forced to make that static geometry non-static?
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Body setup problems

Postby Julio Jerez » Tue Jun 02, 2015 1:48 pm

you use this NewtonCollisionSetMode(collision, 0);

Code: Select all
In the general case, what if I need to have a non-solid trigger (a viewing volume, for example) generate contacts with static/scene geometry? Am I forced to make that static geometry non-static?
you make a dynamic (with mass) body and give it Material the in the call back you reject the contacts. give a force call back the add no force.
this will generate contacts in the call back by will no removes them in the callback.

this is how old version of newton did it
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby aitzolmuelas » Tue Jun 16, 2015 7:26 am

I am currently trying the material callback approach. Just one doubt: when calling NewtonMaterialSetCollisionCallback, for (materialA, materialB) does it also need to be called for (materialB, materialA)? Or is it the same material pair, regardless of order?
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Body setup problems

Postby Julio Jerez » Tue Jun 16, 2015 10:57 am

aitzolmuelas wrote:Just one doubt: when calling NewtonMaterialSetCollisionCallback, for (materialA, materialB) does it also need to be called for (materialB, materialA)? Or is it the same material pair, regardless of order?
not you just call it one, the matrail system is a undirected graph

had you tried the using the shape user data?
Starting with Newton 3.00 I added a user data to the collision instance so that people use it to add per collision shape material. The material system is cool but if has the property that it soon becomes a n body problem with all the possible permutations.

So the original system can be used as a high level per body filter system but the you can use the Material ID to do the Material properties in the callback anyway you like.

and example of the will be a Scene collision, where there is one body but many large collision shapes like building. The original material system will no support that but the per shape user data would.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Body setup problems

Postby aitzolmuelas » Fri Jun 19, 2015 7:49 am

Hi, I am still having trouble getting everything to work the way I need. After your reccomendations and looking at samples, I have tried 2 approaches:

First Approach:
- I tried having the triggers be Dynamic bodies with mass, then discarding contacts in the material callback:
Code: Select all
  NewtonWorldCriticalSectionLock( world, threadIndex );
  for( auto c = NewtonContactJointGetFirstContact( contactJoint ); c; ) {
    auto next_c = NewtonContactJointGetNextContact( contactJoint, c );
    NewtonContactJointRemoveContact( contactJoint, c );
    c = next_c;
  }
  NewtonWorldCriticalSectionUnlock( world );

Is this the proper way to reject contacts? (note I had to add the critical section after a lot of crashing...). The problem with this is that (at least in the stable 3.13) I do not seem to be getting consistent results, particularly when I check NewtonContactJointGetClosestDistance in the trigger manager (the value changes sometimes, i think when contacts start and finish, but it is not updated every frame).

Second Approach:
- I used NewtonWorldConvexCast to try to get the penetration distance for the contacts, but I notice it only seems to work if I cast the shape 'moving' towards things (as if raycasting). I would need to be able to cast the shape 'as-is', no movement or direction, and simply get the contacts info: I saw NewtonWorldCollide, which by the signature seems to be what I am looking for, but it is not implemented (it just asserts false). Is it not yet implemented, or rather obsolete?

What would be the correct way?
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests

cron