GearBlocks
Static Public Member Functions | List of all members
SmashHammer.Scripting.PhysicsProxy Class Reference

Some useful physics functions. More...

Static Public Member Functions

static bool CheckSphere (Vector3Proxy centre, float radius)
 Checks if anything in the scene is inside a spherical region.
 
static bool CheckCapsule (Vector3Proxy centre, Vector3Proxy offsetToEnd, float radius)
 Checks if anything in the scene is inside a capsule region.
 
static bool CheckBox (Vector3Proxy centre, QuaternionProxy orientation, Vector3Proxy extents)
 Checks if anything in the scene is inside a box region.
 
static bool RayCast (Vector3Proxy origin, Vector3Proxy direction, float maxDistance)
 Casts a ray into the scene, finding the first hit point (i.e. the one closest to the ray origin).
 
static int RayCastAll (Vector3Proxy origin, Vector3Proxy direction, float maxDistance)
 Casts a ray into the scene, finding all hit points.
 
static bool SphereCast (Vector3Proxy centre, float radius, Vector3Proxy direction, float maxDistance)
 Casts a sphere into the scene, finding the first hit point (i.e. the one closest to the sphere origin).
 
static int SphereCastAll (Vector3Proxy centre, float radius, Vector3Proxy direction, float maxDistance)
 Casts a sphere into the scene, finding all hit points.
 
static bool CapsuleCast (Vector3Proxy centre, Vector3Proxy offsetToEnd, float radius, Vector3Proxy direction, float maxDistance)
 Casts a capsule into the scene, finding the first hit point (i.e. the one closest to the capsule origin).
 
static int CapsuleCastAll (Vector3Proxy centre, Vector3Proxy offsetToEnd, float radius, Vector3Proxy direction, float maxDistance)
 Casts a capsule into the scene, finding all hit points.
 
static bool BoxCast (Vector3Proxy centre, QuaternionProxy orientation, Vector3Proxy extents, Vector3Proxy direction, float maxDistance)
 Casts a box into the scene, finding the first hit point (i.e. the one closest to the box origin).
 
static int BoxCastAll (Vector3Proxy centre, QuaternionProxy orientation, Vector3Proxy extents, Vector3Proxy direction, float maxDistance)
 Casts a box into the scene, finding all hit points.
 
static float QueryCastHit (int index, out Vector3Proxy position, out Vector3Proxy normal, out int colliderInstanceID)
 Retrieves hit point data from the most recent cast.
 

Detailed Description

Some useful physics functions.

Available in Lua via the "Physics" global, for example:

if Physics.CheckSphere( Vector3.__new( 0, 10, 0 ), 2 ) then
print( 'Something inside sphere!' )
end

Member Function Documentation

◆ CheckSphere()

static bool SmashHammer.Scripting.PhysicsProxy.CheckSphere ( Vector3Proxy  centre,
float  radius 
)
static

Checks if anything in the scene is inside a spherical region.

Parameters
centreThe centre point of the sphere, in world coordinates.
radiusThe radius of the sphere.
Returns
true if anything is inside the sphere; otherwise, false.

◆ CheckCapsule()

static bool SmashHammer.Scripting.PhysicsProxy.CheckCapsule ( Vector3Proxy  centre,
Vector3Proxy  offsetToEnd,
float  radius 
)
static

Checks if anything in the scene is inside a capsule region.

Parameters
centreThe centre point of the capsule, in world coordinates.
offsetToEndA vector from the capsule centre to the centre of one of its end "spheres" (the other end will be offset by -offsetToEnd from the centre), in world coordinates.
radiusThe radius of the capsule.
Returns
true if anything is inside the capsule; otherwise, false.

◆ CheckBox()

static bool SmashHammer.Scripting.PhysicsProxy.CheckBox ( Vector3Proxy  centre,
QuaternionProxy  orientation,
Vector3Proxy  extents 
)
static

Checks if anything in the scene is inside a box region.

Parameters
centreThe centre point of the box, in world coordinates.
orientationThe orientation of the box, in world coordinates.
extentsHalf the size of the box in each dimension.
Returns
true if anything is inside the box; otherwise, false.

◆ RayCast()

static bool SmashHammer.Scripting.PhysicsProxy.RayCast ( Vector3Proxy  origin,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a ray into the scene, finding the first hit point (i.e. the one closest to the ray origin).

Parameters
originThe starting point of the ray, in world coordinates.
directionThe direction of the ray, in world coordinates.
maxDistanceThe maximum distance the ray will "travel".
Returns
true if the ray hits something; otherwise, false.

For information on the hit point, call QueryCastHit, for example:

if Physics.RayCast( Vector3.__new( 0, 10, 0 ), Vector3.Forward, 1000 ) then
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( 0 )
end

◆ RayCastAll()

static int SmashHammer.Scripting.PhysicsProxy.RayCastAll ( Vector3Proxy  origin,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a ray into the scene, finding all hit points.

Parameters
originThe starting point of the ray, in world coordinates.
directionThe direction of the ray, in world coordinates.
maxDistanceThe maximum distance the ray will "travel".
Returns
The number of hit points found.

For information on the hit point, call QueryCastHit, for example:

local numHits = Physics.RayCastAll( Vector3.__new( 0, 10, 0 ), Vector3.Forward, 1000 )
for i = 0, numHits - 1 do
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( i )
end

◆ SphereCast()

static bool SmashHammer.Scripting.PhysicsProxy.SphereCast ( Vector3Proxy  centre,
float  radius,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a sphere into the scene, finding the first hit point (i.e. the one closest to the sphere origin).

Parameters
centreThe starting centre point of the sphere, in world coordinates.
radiusThe radius of the sphere.
directionThe cast direction, in world coordinates.
maxDistanceThe maximum distance the sphere will "travel".
Returns
true if the sphere hits something; otherwise, false.

For information on the hit point, call QueryCastHit, for example:

if Physics.SphereCast( Vector3.__new( 0, 10, 0 ), 2, Vector3.Forward, 1000 ) then
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( 0 )
end

◆ SphereCastAll()

static int SmashHammer.Scripting.PhysicsProxy.SphereCastAll ( Vector3Proxy  centre,
float  radius,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a sphere into the scene, finding all hit points.

Parameters
centreThe starting centre point of the sphere, in world coordinates.
radiusThe radius of the sphere.
directionThe cast direction, in world coordinates.
maxDistanceThe maximum distance the sphere will "travel".
Returns
The number of hit points found.

For information on the hit point, call QueryCastHit, for example:

local numHits = Physics.SphereCastAll( Vector3.__new( 0, 10, 0 ), 2, Vector3.Forward, 1000 )
for i = 0, numHits - 1 do
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( i )
end

◆ CapsuleCast()

static bool SmashHammer.Scripting.PhysicsProxy.CapsuleCast ( Vector3Proxy  centre,
Vector3Proxy  offsetToEnd,
float  radius,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a capsule into the scene, finding the first hit point (i.e. the one closest to the capsule origin).

Parameters
centreThe starting centre point of the capsule, in world coordinates.
offsetToEndA vector from the capsule centre to the centre of one of its end "spheres" (the other end will be offset by -offsetToEnd from the centre), in world coordinates.
radiusThe radius of the capsule.
directionThe cast direction, in world coordinates.
maxDistanceThe maximum distance the capsule will "travel".
Returns
true if the capsule hits something; otherwise, false.

For information on the hit point, call QueryCastHit, for example:

if Physics.CapsuleCast( Vector3.__new( 0, 10, 0 ), Vector3.__new( 0, 3, 0 ), 2, Vector3.Forward, 1000 ) then
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( 0 )
end

◆ CapsuleCastAll()

static int SmashHammer.Scripting.PhysicsProxy.CapsuleCastAll ( Vector3Proxy  centre,
Vector3Proxy  offsetToEnd,
float  radius,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a capsule into the scene, finding all hit points.

Parameters
centreThe starting centre point of the capsule, in world coordinates.
offsetToEndA vector from the capsule centre to the centre of one of its end "spheres" (the other end will be offset by -offsetToEnd from the centre), in world coordinates.
radiusThe radius of the capsule.
directionThe cast direction, in world coordinates.
maxDistanceThe maximum distance the capsule will "travel".
Returns
The number of hit points found.

For information on the hit point, call QueryCastHit, for example:

local numHits = Physics.CapsuleCastAll( Vector3.__new( 0, 10, 0 ), Vector3.__new( 0, 3, 0 ), 2, Vector3.Forward, 1000 )
for i = 0, numHits - 1 do
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( i )
end

◆ BoxCast()

static bool SmashHammer.Scripting.PhysicsProxy.BoxCast ( Vector3Proxy  centre,
QuaternionProxy  orientation,
Vector3Proxy  extents,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a box into the scene, finding the first hit point (i.e. the one closest to the box origin).

Parameters
centreThe starting centre point of the box, in world coordinates.
orientationThe orientation of the box, in world coordinates.
extentsHalf the size of the box in each dimension.
directionThe cast direction, in world coordinates.
maxDistanceThe maximum distance the box will "travel".
Returns
true if the box hits something; otherwise, false.

For information on the hit point, call QueryCastHit, for example:

if Physics.BoxCast( Vector3.__new( 0, 10, 0 ), Quaternion.Identity, Vector3.__new( 2, 3, 2 ), Vector3.Forward, 1000 ) then
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( 0 )
end

◆ BoxCastAll()

static int SmashHammer.Scripting.PhysicsProxy.BoxCastAll ( Vector3Proxy  centre,
QuaternionProxy  orientation,
Vector3Proxy  extents,
Vector3Proxy  direction,
float  maxDistance 
)
static

Casts a box into the scene, finding all hit points.

Parameters
centreThe starting centre point of the box, in world coordinates.
orientationThe orientation of the box, in world coordinates.
extentsHalf the size of the box in each dimension.
directionThe cast direction, in world coordinates.
maxDistanceThe maximum distance the box will "travel".
Returns
The number of hit points found.

For information on the hit point, call QueryCastHit, for example:

local numHits = Physics.BoxCastAll( Vector3.__new( 0, 10, 0 ), Quaternion.Identity, Vector3.__new( 2, 3, 2 ), Vector3.Forward, 1000 )
for i = 0, numHits - 1 do
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( i )
end

◆ QueryCastHit()

static float SmashHammer.Scripting.PhysicsProxy.QueryCastHit ( int  index,
out Vector3Proxy  position,
out Vector3Proxy  normal,
out int  colliderInstanceID 
)
static

Retrieves hit point data from the most recent cast.

Parameters
indexIndex of the hit point to query.
positionReturns the hit point position, in world coordinates.
normalReturns the hit point normal, in world coordinates.
colliderInstanceIDReturns an ID for the collider that was hit.
Returns
The distance from the cast origin to the hit point.

Using the collider instance ID, if a part was hit it can be retrieved from the PartColliderRegistry, for example:

if Physics.RayCast( Vector3.__new( 0, 10, 0 ), Vector3.Forward, 1000 ) then
local distance, position, normal, colliderInstanceID = Physics.QueryCastHit( 0 )
local part = PartColliderRegistry.GetPart( colliderInstanceID )
if part then
print( 'Part: ' .. part.FullDisplayName )
end
end