wiki.sine.space | sinespace

Scripting/SRay

From wiki.sine.space
Revision as of 04:39, 14 July 2021 by Voidtech (Talk | contribs)

Jump to: navigation, search

Attributes

Origin

SVector Origin ;

The origin point of the ray.

local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))
Space.Log("Origin "..ray.Origin.ToString())


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

Direction

SVector Direction ;

The direction of the ray.

local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))
Space.Log("Direction "..ray.Direction.ToString())


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