pXent_settype (ENTITY* entity, var type, var hull )

Registers / unregisters a rigid physics object. After registering, the entity will be under control of the physics system and a "PhysX actor" is created. After unregistering, the actor is deleted and the entity is no longer controlled by physics.

Parameters:

entity Entity pointer to be registered / unregistered, or NULL for registering the level.
type PH_STATIC = register the entity as a static obstacle.
PH_RIGID = register the entity as a dynamic rigid body that can move (model entities only).
PH_CHAR = register the entity as a character controller (model entities only).
0 = unregister the entity from the physics system.
hull PH_BOX - Rectangular, box-shaped hull.
PH_SPHERE - Round hull.
PH_CAPSULE - Cylindrical collision hull with a semisphere at the top and bottom.
PH_POLY
- Polygonal hull, for static (PH_STATIC) actors only.
PH_CONVEX - Simple convex polygonal hull for dynamic actors - 256 polygons maximum.
PH_TERRAIN - Heightmap; PH_POLY often works better for terrain.
PH_PLANE - Ground plane at position z=0.
Add PH_MODIFIED for re-registering a modified PH_POLY, PH_TERRAIN, or PH_CONVEX hull.

Returns:

Current number of PhysX actors if successful, 0 otherwise.

Remarks:

Speed:

Slow

Example 1:

ENTITY* myCrate;
// ...
// on startup
myCrate = ent_create( "crate.mdl", nullvector, any_function );
pXent_settype( myCrate, PH_RIGID, PH_BOX ); 
pXent_settype( myCrate, 0, 0 );
// ...
// during gameplay let's have fun with a crate:
var position;
pXent_settype( myCrate, PH_RIGID, PH_BOX );
position= myCrate.x; // this will give you an approximate position
//myCrate.x = position + 10; // this won't work!
pXent_settype( myCrate, 0, 0 );
myCrate.x = position + 10; // unregistered - now we can change the position

pXent_settype( myCrate, PH_RIGID, PH_BOX ); // restart from new position

Example 2:

function f_ball()
{
  VECTOR vKick;
  vec_set(vKick,vector(300,0,100));
  pXent_settype(my, PH_RIGID, 1);
  pXent_setfriction(my, 100);
  pXent_setelasticity(my, 10);
  vec_rotate(vKick,camera.pan);
  pXent_addvelcentral(my, vKick);
}

function on_mouse_right_event()
{
  while (mouse_left) {wait (1);}
  ENTITY* ball = ent_create ("explosion.mdl", camera.x, f_ball);
  set(ball,PASSABLE);
}

See also:

PhysX FAQ, pXent_addshape, pXent_removeshape, pXent_cloth