phent_addforceglobal (ENTITY* entity,VECTOR* vForce,VECTOR* vPos
);
phent_addforcelocal (ENTITY* entity,VECTOR* vForce,VECTOR* vPos );
Force and torque ("angular force") will be applied to the specified entity,
at global (world coordinates) or local (entity coordinates) position vPos.
The force vector is independent of the objects current orientation. It
is not checked whether the position is actually inside the entity, so
by choosing a vPos far
away from the entity, you can give it a strong spin. If vPos is
exactly at the object's center of mass,
no spinning will occur (consider using phent_addcentralforce in
this case). phent_addforceglobal gives the same result as
calling both phent_addcentralforce and phent_addtorqueglobal with
the same parameters.
Parameters:
entity |
Entity to be affected |
vForce |
Vector determining the force to be exerted on entity |
vPos |
Vector specifying the point where vForce is applied |
Returns:
1 if successful, 0 otherwise.
Remarks:
-
Force accelerates entities according to the Newton formula speed = time
* force / mass. Thus for higher acceleration or heavier entities you have
to use a stronger force or apply them during a longer time.
- Avoid applying forces for a frame rate dependent time. In the worst case
- when applying a force for one frame cycle only (time_frame)
- the entities' speed will be detemined by the frame rate. When the engine
frame rate is higher than the physics update rate (►ph_fps_max_lock),
it can even happen that no physics update occurs in the frame cycle and
the entity is not accelerated at all.
- If you want to accelerate the entity to a certain speed regardeless of
the frame rate, use phent_addvelcentral instead.
- Forces are additive, i.e. calling this function twice doubles the force.
- For efficiency reasons you should prefer phent_addcentralforce to phent_addforceglobal,
when possible.
- This function also works with PH_WAVE entities.
When used with such vecpoint is a global (=world) coordinate. vecforce.z
gives the amount
of initial water displacement in Z direction. The valid range for
vecforce.z is -1 to +1, where this value is relative to the general
terrain size. E.g. a value of 1 corresponds to the distance from
one vertex to its neighbor in x direction; a value of 0.5 then would
be half this distance. It's a good idea to use small values here.
Speed:
Fast
Example:
ph_setgravity(vector(0,0,-386));
var mass = 10;
phent_settype( my, PH_RIGID, PH_BOX );
phent_setmass( mass );
// force is three times as strong as gravity's pull, so we can lift up the entity, while pressing a key
while (key_pressed( key_for_str("L")) )
{
VECTOR vTemp;
vec_set(vTemp,vector(0,0,-386)); //gravity
vec_scale( vTemp, -3 * mass );
phent_addforceglobal( myCrate, nullvector, vTemp );
wait(1);
}
See also:
ph_selectgroup
► latest
version online