Loading...
 
Physics Ray Casting        

Physics Ray Casting

These functions cast in a straight line from a point, either a line, or a shape, and report collisions from the scene.

Return values

For each collision, 4 values are returned:
  • The distance cast before collision, as a proportion of the given distance between 0 and 1 (number)
  • The object hit (RigidBody)
  • The normal of the surface at the point where it was hit (vector3)
  • The physical material name (string)
If no collisions, no values are returned

Physics_cast

physics_cast(pos, ray, nearest_only, flags, blacklist...)

Cast a ray, i.e. a point of zero cross-sectional area.
  • pos (vector3) - Is the position from where the ray is cast, worldspace
  • ray (vector3) - The direction vector along which to cast, worldspace
  • nearest_only - Whether to return the nearest collision or all collisions
  • flags - a bitwise union of flags, currently 1 meaning ignore dynamic objects
  • blacklist - a varargs list of specific objects to ignore when computing collisions

Sweeping objects

These calls cast a 3d shape instead of a zero volume point. Orientation, if required, is a quaternion. The dimensions of the box are given with a vector3. The rest of the arguments are the same as physics_cast.
physics_sweep_sphere(radius, ...)
physics_sweep_cylinder(radius, height, orientation, ...)
physics_sweep_box(size, orientation, ...)