pXent_move (ENTITY* entity, VECTOR* vReldist, VECTOR* vAbsdist);
Directly move a physics entity or character controller globally (in world coordinates) and locally (in entity coordinates).
Parameters:
entity |
registered physics entity, kinematic entity, or character controller. |
vReldist |
Move distance vector in entity coordinates. |
vAbsdist |
Move distance vector in world coordinates. |
Returns:
Nonzero on PH_CHAR collisions, 0 otherwise.
Remarks:
- Kinematic entities (NX_BF_KINEMATIC) and character controllers (PH_CHAR)
are not affected by forces, but move with collision detection. Kinematic entities can push obstacles out of the way; character controllers can themselves be affected by obstacles.
When moving a character controller, pXent_move returns nonzero when the character collided with something.
- Depending on friction, relative position changes must exceed a certain threshold for moving the entity. Kinematic entities move by applying an internal force, which requires several frames for completing a move. This reduces their effective speed compared to objects that move the whole distance in one frame.
- When this function is called for normal (non-kinematic) physics entities, the entity is immediately placed to the new position, without collision detection. No entities must be moved into other entities, thus causing interpenetration (an invalid physical state). Entities connected with joints can only be moved closer to each other and in a way that the joint constraint is not violated. Static physics entities must not be moved at all.
- This function replaces the old pXent_movechar, pXent_moveglobal, and pXent_movelocal functions that were abandoned.
Speed:
Medium
Example:
#include <default.c>
#include <ackphysx.h
// Example of the four move modes with and without physics
// comment one of them in for testing
//#define RIGID
//#define KINEMATIC
#define CHARACTER
//#define C_MOVE
function main()
{
shadow_stencil = 1;
physX_open();
level_load("");
vec_set(camera.x,vector(-1000,0,600));
vec_set(camera.pan,vector(0,-40,0));
ENTITY *ground = ent_createterrain(NULL, NULL, 32, 32, 100);
bmap_fill(bmap_for_entity(ground, 0),COLOR_GREEN,100);
pXent_settype(ground,PH_STATIC,PH_TERRAIN);
pXent_setfriction(ground,0);
ENTITY *actor = ent_create(CUBE_MDL, vector(0, 0, 20), NULL);
vec_set(actor.scale_x,vector(5,2,1));
vec_set(actor.blue,COLOR_RED);
set(actor,LIGHT|SHADOW);
#ifdef RIGID
pXent_settype(actor, PH_RIGID, PH_BOX);
#endif
#ifdef KINEMATIC
pXent_settype(actor, PH_RIGID, PH_BOX);
pXent_setbodyflag(actor,NX_BF_KINEMATIC,1);
#endif
#ifdef CHARACTER
pXent_settype(actor, PH_CHAR, PH_BOX);
#endif
wait(-1); // wait with moving until objects are loaded and time_step is settled
while(1)
{
actor.skill1 += 5*time_step; // angle
actor.skill4 = 15*time_step; // speed
#ifdef C_MOVE
vec_set(actor.pan,actor.skill1);
c_move(actor,actor.skill4,NULL,0);
#else
pXent_rotate(actor,NULL,actor.skill1);
pXent_move(actor,actor.skill4,NULL);
#endif
wait(1);
}
}
See also:
PH_CHAR, NX_BF_KINEMATIC, pXent_rotate, pXent_setposition, c_move