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:
- This function has to
be called after setting the object's position and scale, and before executing any other pXent_ functions.
- The first time a
specific entity is registered, this instruction is slow when a collision mesh must be built.
-
When a physics entity is unregistered, all its physics properties, such as speed, joints, type etc. are lost. Entities must be unregistered before changing the level.
Normally this is automatically handled by physX_open.
- While you can
continue to read a physics entities' position and angles,
you can no longer directly change its position (x,y,z), orientation
(pan, tilt, roll), or scale. Use pXent_addforce
or similar function to impact forces on the entity instead. If you need to directly
change position or orientation,
call
pXent_move or pXent_setposition, or temporarily disable the
entity using pXent_enable.
- The collision hull uses the real entity size, regardless of min_x / max_x. For a different sized hull, set the entity's scale_x vector to the desired scale factors before calling pXent_settype, and set it back afterwards.
- Don't use PH_POLY
hulls for dynamic actors. For creating dynamic actors with complex shapes, either use PH_CONVEX, or call pXent_addshape.
-
The mesh for a PH_CONVEX hull can be concave - the hull is then automatically converted to convexity by filling gaps and dips in the mesh.
- Don't
use pXent_settype for wheels - create wheels with pXcon_add.
- Very small dynamic objects that can move by more that their half diameter per frame require CCD collision detection.
- When using PH_CHAR, put a
wait(1) pause after pXent_settype before calling pXent_move. PH_CHAR works only with a PH_BOX or PH_CAPSULE hull (all other hulls will set PH_CAPSULE).
A
PH_CHAR can't collide with a PH_PLANE - it can only walk on a terrain or static bodies.
Use pXent_setskinwidth before calling pXent_settype for setting the skin width of all subsequent character controllers; the skin width determines the maximum height of steps that the character can climb.
- The NxActor pointer of the physics actor is stored in the
body parameter of the ENTITY struct.
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