phent_settype ( ENTITY*, var type, var hull );
Registers / unregisters an entity with the physics system. After registering,
starting with the current frame the entity will be under control of the physics
system (if the group bitmask is set appropriately by ph_selectgroup).
After unregistering, the entity is reversed to a 'standard' Gamestudio entity
and is no longer controlled by physics.
Parameters:
ENTITY* |
Entity pointer to be registered / unregistered. |
type |
PH_RIGID to register the entity as a rigid body.
PH_WAVE P to register terrain
as dynamic water surface.
0 for unregistering the entity from the physics system. |
hull |
Collision hull of this object, PH_BOX, PH_SPHERE, PH_CYLINDER
or PH_POLY. |
Returns:
1 if successful, 0 otherwise.
Remarks:
- This function has
to be called before executing any other phent_ functions.
- The first time a
specific entity is registered, this instruction is slow because
some calculations need to be done. Thus it makes sense to register
all potential physical entity types at level load time and then
unregistering them again. During gameplay the registration will
then be a lot quicker for all entities of that type.
- While you can continue
to read a registered entities' position and orientation, you can
no longer directly change its position (x,y,z), orientation (pan,
tilt, roll), or scale. Use
phent_addforce to impart forces on the entity instead. If you need
to directly change position or orientation, you can temporarily disable
the entity using phent_enable.
-
Do not use PH_POLY
or PH_CYLINDER hulls for moving entities. Use PH_SPHERE for the wheels
of a vehicle.
- PH_WAVE converts
a terrain entity to a dynamic water surface. The resolution and smoothness
depends on the underlying terrain's vertex grid. The more vertices
the smoother and slower the simulation will be. Some functions
are available for controlling water surfaces: phent_setdamping, phent_addforcelocal and phent_addobstruction.
- The A6 Commercial Edition C allows
to register only one entity with the physics system. For registering
another, the first one must be unregistered first.
This restriction
does not apply to A7 or lite-C.
Speed:
Slow / Medium
Edition:
A6 C
P
A7 P for
PH_WAVE
Example:
ENTITY* myCrate;
// ...
// on startup
myCrate = ent_create( "crate.mdl", nullvector, any_function );
phent_settype( myCrate, PH_RIGID, 0 );
phent_settype( myCrate, 0, 0 );
// ...
// during gameplay let's have fun with a crate:
var position;
phent_settype( myCrate, PH_RIGID, PH_BOX );
position= myCrate.x; // this will give you an approximate position
//myCrate.x = position + 10; // this won't work!
phent_settype( myCrate, 0, 0 );
myCrate.x = position + 10; // unregistered - now we can change the position
phent_settype( myCrate, PH_RIGID, PH_BOX ); // restart from new position
See also:
phent_addforceglobal,
phent_addforcelocal, ph_selectgroup
► latest
version online