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)
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)
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)
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)
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.
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)