Skip to content

Collision

groverburger edited this page Dec 23, 2021 · 6 revisions

Collisions

Last updated for g3d version 1.5.1

g3d.collisions.closestPoint(verts, transform, x, y, z)

Finds the closest point to the point given on the mesh defined by the vertex list given, interpreted as triangles.
Returns the distance from the source to the closest point, the closest point, and the normal vector in the format distance, x, y, z, nx, ny, nz.

Arguments:

  • verts
    • the list of vertices defining triangles on which the closest point will be found
  • transform
    • a table containing a translation and a scale vector which transform the coordinates of the vertices given, this argument is optional
  • x
    • the x component of the point
  • y
    • the y component of the point
  • z
    • the z component of the point

g3d.collisions.isPointInside(verts, transform, x, y, z)

Detects whether the point is inside the mesh defined by the vertex list given, interpreted as triangles.
Returns either true or false.

Arguments:

  • verts
    • the list of vertices defining triangles on which the closest point will be found
  • transform
    • a table containing a translation and a scale vector which transform the coordinates of the vertices given, this argument is optional
  • x
    • the x component of the point
  • y
    • the y component of the point
  • z
    • the z component of the point

g3d.collisions.rayIntersection(verts, transform, x1, y1, z1, x2, y2, z2)

Detects whether the ray specified intersects any of the triangles in the vertex list given.
Returns the distance from the source to the intersection point, the intersection point, and the normal vector in the format distance, x, y, z, nx, ny, nz. If an intersection point does not exist, nil is returned instead.

Arguments:

  • verts
    • the list of vertices defining triangles on which the closest point will be found
  • transform
    • a table containing a translation and a scale vector which transform the coordinates of the vertices given, this argument is optional
  • x1
    • a number representing the first x coordinate of the ray
  • y1
    • a number representing the first y coordinate of the ray
  • z1
    • a number representing the first z coordinate of the ray
  • x2
    • a number representing the second x coordinate of the ray
  • y2
    • a number representing the second y coordinate of the ray
  • z2
    • a number representing the second z coordinate of the ray

g3d.collisions.sphereIntersection(verts, transform, x, y, z, radius)

Detects whether the sphere specified intersects any of the triangles in the vertex list given.
Returns the distance from the source to the intersection point, the intersection point, and the normal vector in the format distance, x, y, z, nx, ny, nz. If an intersection point does not exist, nil is returned instead.

Arguments:

  • verts
    • the list of vertices defining triangles on which the closest point will be found
  • transform
    • a table containing a translation and a scale vector which transform the coordinates of the vertices given, this argument is optional
  • x
    • the x component of the center of the sphere
  • y
    • the y component of the center of the sphere
  • z
    • the z component of the center of the sphere
  • radius
    • the radius of the sphere

g3d.collisions.capsuleIntersection(verts, transform, x1, y1, z1, x2, y2, z2, radius)

Detects whether the capsule specified intersects any of the triangles in the vertex list given.
Returns the distance from the source to the intersection point, the intersection point, and the normal vector in the format distance, x, y, z, nx, ny, nz. If an intersection point does not exist, nil is returned instead.

Arguments:

  • verts
    • the list of vertices defining triangles on which the closest point will be found
  • transform
    • a table containing a translation and a scale vector which transform the coordinates of the vertices given, this argument is optional
  • x1
    • a number representing the x component of the tip of the capsule
  • y1
    • a number representing the y component of the tip of the capsule
  • z1
    • a number representing the z component of the tip of the capsule
  • x2
    • a number representing the x component of the base of the capsule
  • y2
    • a number representing the y component of the base of the capsule
  • z2
    • a number representing the z component of the base of the capsule
  • radius
    • the radius of the capsule