SPhysics

Index

Functions Index

Function Name

SPhysicsHit[] RayCast (SVector origin, SVector normal, float distance, SLayerMask layerMask=null)

SPhysicsHit RayCastSingle (SVector origin, SVector normal, float distance, SLayerMask layerMask=null)

SPhysicsHit[] SphereCast (SVector origin, float radius, float distance, SVector direction, SLayerMask layerMask=null) SPhysicsHit[] SphereCast (SVector origin, float radius, float distance, SLayerMask layerMask=null)

SPhysicsHit[] CapsuleCast (SVector origin, SVector end, float radius, float distance, SVector up, SLayerMask layerMask=null) SPhysicsHit[] CapsuleCast (SVector origin, SVector end, float radius, float distance, SLayerMask layerMask=null)

SPhysicsHit[] BoxCast (SVector origin, SVector extents, SVector direction, SQuaternion orientation, float distance, SLayerMask layerMask=null)

Properties Index

Property Name

SVector Gravity get set

Functions

RayCast

SPhysicsHit[] RayCast (SVector origin, SVector normal, float distance, SLayerMask layerMask=null)

Raycasts from origin along normal, distance meters - and returns a list of collisions in distance order (closest first)

ParameterTypeDescription

origin

SVector

normal

SVector

distance

SVector

layerMask

SLayerMask

Include a layer mask if you do not want to use viewer's defaults.

tableSPhysicsHit = Space.Physics.RayCast(Vector.New(0,0,0), Vector.New(1,0,0), 2.0)
local trans=Space.Host.ExecutingObject
function Raycast()
    local rays = Space.Physics.RayCast(trans.WorldPosition,trans.Forward,50)
    if(rays~=nil and #rays>0) then
for i=0,#rays - 1 do
    Space.Log(rays[i].Object.Name.." i = "..i)
end
    end
end
trans.OnUpdate(Raycast)

RayCastSingle

SPhysicsHit RayCastSingle (SVector origin, SVector normal, float distance, SLayerMask layerMask=null)

Raycasts from origin along normal, distance meters - and returns the first collision.

ParameterTypeDescription

SPhysicsHit = Space.Physics.RayCastSingle(Vector.New(0,0,0), Vector.New(1,0,0), 2.0)
local trans=Space.Host.ExecutingObject
function RaycastSingle()
    local ray=Space.Physics.RayCastSingle(trans.WorldPosition,trans.Forward,50)
    if(ray~=nil and ray.ContainsHit==true) then
Space.Log(ray.Object.Name)     end
end
trans.OnUpdate(RaycastSingle)
 --this script will make this object jump to wherever you right click
--(Example: moving objects with right click )

thisGameObject = Space.Host.ExecutingObject


OnUpdate = function()
  if Space.Input.GetMouseDown(1) then
   clickRay = Space.Camera.ScreenCoordinatesToRay(Space.Input.MousePosition)
  rayCastHit = Space.Physics.RayCastSingle(clickRay.Origin, clickRay.Direction, 50.0)
  thisGameObject.WorldPosition = rayCastHit.Position
  end
end

thisGameObject.SubscribeToEvents()
thisGameObject.OnUpdate(OnUpdate)  

SphereCast

SPhysicsHit[] SphereCast (SVector origin, float radius, float distance, SVector direction, SLayerMask layerMask=null) SPhysicsHit[] SphereCast (SVector origin, float radius, float distance, SLayerMask layerMask=null)

Sweeps from origin in a spherical ray 'radius' wide, and returns the list of collided objects

ParameterTypeDescription

tableSPhysicsHit = Space.Physics.SphereCast(Vector.New(0,0,0), 3.0, 2.0, Vector.New(1,0,0))
--or
tableSPhysicsHit = Space.Physics.SphereCast(Vector.New(0,0,0), 3.0, 2.0)
local trans=Space.Host.ExecutingObject
function SphereRaycast()
    local center=trans.WorldPosition + Vector.New(0.5,0.5,0.5)
    local rays=Space.Physics.SphereCast(center,10,10,trans.Forward)
    if rays~=nil and #rays>0 then
for i=0,#rays - 1 do
    Space.Log(rays[i].Object.Name.." i = "..i)
end
    end
end
trans.OnUpdate(SphereRaycast)

CapsuleCast

SPhysicsHit[] CapsuleCast (SVector origin, SVector end, float radius, float distance, SVector up, SLayerMask layerMask=null) SPhysicsHit[] CapsuleCast (SVector origin, SVector end, float radius, float distance, SLayerMask layerMask=null)

Sweeps a capsule from origin to end, radius wide and returns a list of collisions.

ParameterTypeDescription

tableSPhysicsHit = Space.Physics.CapsuleCast(Vector.New(0,0,0),Vector.New(0,5,0), 3.0, 2.0, Vector.New(1,0,0))
--or
tableSPhysicsHit = Space.Physics.CapsuleCast(Vector.New(0,0,0),Vector.New(0,5,0), 3.0, 2.0)
local trans=Space.Host.ExecutingObject
function CapsuleCast()
    local startp=trans.WorldPosition
    local endp=startp+trans.Up*10
    local rays=Space.Physics.CapsuleCast(startp,endp,1,10,trans.Up)
    if rays~=nil and #rays>0 then
for i=0,#rays - 1 do
    Space.Log(rays[i].Object.Name.." i = "..i)
end
    end
end
trans.OnUpdate(CapsuleCast)

BoxCast

SPhysicsHit[] BoxCast (SVector origin, SVector extents, SVector direction, SQuaternion orientation, float distance, SLayerMask layerMask=null)

Sweeps a box defined by origin+halfExtents along direction, distance meters with a orientation matching orientation - and returns a list of collisions in distance order.

ParameterTypeDescription

tableSPhysicsHit = Space.Physics.BoxCast(Vector.New(0,0,0),Vector.New(1,1,1), Vector.New(0,1,0), Quaternion.New(0,60,0), 10.0)
local trans=Space.Host.ExecutingObject
function BoxCast()
    local center=trans.WorldPosition + Vector.New(0.5,0.5,0.5)
    local endp=local extents=Vector.new(2,2,2)
    local rays=Space.Physics.BoxCast(center,extents,trans.Forward,Quaternion.Identity,2)
    if rays~=nil and #rays>0 then
for i=0,#rays - 1 do
    Space.Log(rays[i].Object.Name.." i = "..i)
end
    end
end
trans.OnUpdate(BoxCast)

Properties

Gravity

SVector Gravity get set

The gravity applied to all rigid bodies in the Scene.

Gravity can be turned off for an individual Rigidbody using its UseGravity property.

Space.Physics.Gravity = Vector.New(0,-1.0,0)

Last updated

Sinespace® is a registered trademark of Sine Wave Entertainment Ltd, All Rights Reserved.