collision detect

jarwulf

06-07-2010 08:46:18

Hi, I want collision detection for a moving character. What I have now is a cube representing the character. The problem with this is that the object tumbles when applying an x or z force etc. So the attached mesh character spins around when I would like for it to simply move from point a to point b and the view camera which is set to follow the character from a set distance tumbles along with it. How would I implement a better solution such as a forcefield around the mesh?

betajaen

06-07-2010 10:30:35

There are three ways:

- Each frame setting the linear/angular momentum to zero each frame, and increasing the linear/angular damping to max. This will reduce all movement and collision response to zero, it may also let the character through other objects.

- Use a KinematicActor or KinematicBody this will let it go through other objects or bodies but if your careful enough it would work. Internally the PhysX character controller uses this, it does sweep test when the character has moved (or something has moved around it), then decides if it has hit something above, to the sides or below then plan the next movement based on the collisions.

- Use a PhysX Character Controller. Detritus has this implemented now. I'm working on a visual representation with animation support with Critter right now, but if you want to get into it straight away you can do so, but you would have to create and update the node position of the character every frame. It isn't difficult but Critter would normally do that for you.

If you need further help, I'm happy to answer. ;)

jarwulf

06-07-2010 19:42:58

There are three ways:

- Each frame setting the linear/angular momentum to zero each frame, and increasing the linear/angular damping to max. This will reduce all movement and collision response to zero, it may also let the character through other objects.

- Use a KinematicActor or KinematicBody this will let it go through other objects or bodies but if your careful enough it would work. Internally the PhysX character controller uses this, it does sweep test when the character has moved (or something has moved around it), then decides if it has hit something above, to the sides or below then plan the next movement based on the collisions.

- Use a PhysX Character Controller. Detritus has this implemented now. I'm working on a visual representation with animation support with Critter right now, but if you want to get into it straight away you can do so, but you would have to create and update the node position of the character every frame. It isn't difficult but Critter would normally do that for you.

If you need further help, I'm happy to answer. ;)


The problem is I don't want it to go through objects. The ideal solution would be a nxs box which surrounds the visual mesh and slides to wherever its going without tumbling. Is there a way to make something like this?


Later on as time permits I'd replace this with a ragdoll or capsule based character but I figured the above would be a quick and dirty compromise.

betajaen

06-07-2010 19:49:54

Alrighty,

Set Linear and Angular Damping to high (1.0), and then enable the freeze rotation flags in DynamicRigidBodyFlags of the Actor/Body so it won't tip over.

Also; don't use forces, set the linear velocity directly so you have absolute control.

jarwulf

09-07-2010 19:48:12

Alrighty,

Set Linear and Angular Damping to high (1.0), and then enable the freeze rotation flags in DynamicRigidBodyFlags of the Actor/Body so it won't tip over.

Also; don't use forces, set the linear velocity directly so you have absolute control.


Okay, it works but there may be a potential problem here. I generally don't want the cube to tumble around when I'm push it but in order to be able to climb or descend on ramps smoothly you can't have its rotationflag frozen right? Or does it even matter?

betajaen

09-07-2010 20:01:41

It would face upwards if the frozen flags are enabled, and doesn't really matter with ramps. However; If you want the player to take on the normal plane of the ramp then the frozen flags wouldn't allow this.

jarwulf

14-07-2010 04:52:52

It would face upwards if the frozen flags are enabled, and doesn't really matter with ramps. However; If you want the player to take on the normal plane of the ramp then the frozen flags wouldn't allow this.

Hmm...this approach is going to be harder than I thought. The rotate function doesn't work on the attached mesh anymore even with rotation around y enabled so I guess I'll just have to add some velocity to the cube to spin it in the direction I want..

jarwulf

14-07-2010 06:28:11

alright, even when I use setAngularvelocity I'm not getting a rotation when the body is in contact with the ground. Only when its up in the air. any suggestions?

betajaen

14-07-2010 09:07:54

If you have the frozen rotation flags enabled, it won't turn if it's directly controlled by the user, or rotation changed by torque. It won't turn. You may be able to set the orientation to turn your character. But what you could do is disable the yaw rotation flag whilst it is in the air, and turn it then.

jarwulf

14-07-2010 20:59:33

If you have the frozen rotation flags enabled, it won't turn if it's directly controlled by the user, or rotation changed by torque. It won't turn. You may be able to set the orientation to turn your character. But what you could do is disable the yaw rotation flag whilst it is in the air, and turn it then.


I froze rotation except for the y axis. But the figure won't turn along this axis except thru collisions or while in the air. Maybe the character controller will be a better idea. When do you think the finalized sdk will be released?