pXent_raycast (ENTITY* entity, VECTOR* dir, var ShapesType, var hitflag): void*

Returns the first shape that is hit along the ray or a specific information about the shape depending on the hitflag you set.


entity Entity pointer, gives start position of the ray
dir Direction of the ray
ShapesType Entities that can get hit by the ray:
NX_STATIC_SHAPES = hit static shapes only.
NX_DYNAMIC_SHAPES = hit dynamic shapes only.
NX_ALL_SHAPES = hit both static & dynamic shapes.
hitflag Allows you to specify which field of Raycast Types you are interested in.
NX_RAYCAST_ENTITY = the function returns the closest physics entity that was hit by the ray. (default )
NX_RAYCAST_IMPACT = the function returns the impact vector in world coords.
NX_RAYCAST_NORMAL = the function returns the normal vector in world coords.
NX_RAYCAST_FACE_INDEX = the function returns the faceID , internalFaceID and 0 in a vector.
NX_RAYCAST_DISTANCE = the function returns the distance between the hit shape and the entity position.
NX_RAYCAST_UV = the function returns the U and V coords. And 0 in a vector.
NX_RAYCAST_FACE_NORMAL = the function returns the normal vector in world coords.
NX_RAYCAST_MATERIAL = the function returns the material index of the shape.


ENTITY* or VECTOR*, depending on the hitflag




VECTOR* worldImpact = pXent_raycast ( pRL, vector(0,0,-1), NX_STATIC_SHAPES, NX_RAYCAST_IMPACT);
if(worldImpact.z < -800)
  pXent_addforceglobal (my, vector(0,0,1000), pRL.x );  
// display the "look at" entities
VECTOR* lookat = vector(1,0,0);
hit_ent = pXent_raycast(my, lookat, NX_ALL_SHAPES, NX_RAYCAST_ENTITY); 
str_cpy(format,"I see ");
  str_for_entfile (temp_str, hit_ent);
  str_cpy(format,"I see a ");
vec_to_screen ( temp, camera);

pan_setdigits(char_panel, 1, temp.x, temp.y, format, my_font, 0, 0);

See also:

pXcon_add, pXcon_getposition