wiki.sine.space | sinespace

Difference between revisions of "Scripting/SRay"

From wiki.sine.space
Jump to: navigation, search
(Created page with "=Attributes= {{ScriptFunction|SVector|Origin|;|The origin point of the ray.|5= local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))<br> Space.Log("Origin "..r...")
 
Line 4: Line 4:
 
local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))<br>
 
local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))<br>
 
Space.Log("Origin "..ray.Origin.ToString())
 
Space.Log("Origin "..ray.Origin.ToString())
}}
+
|6=<pre>  --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)  </pre>}}
  
 
{{ScriptFunction|SVector|Direction|;|The direction of the ray.|5=
 
{{ScriptFunction|SVector|Direction|;|The direction of the ray.|5=
 
local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))<br>
 
local ray=Space.Camera.ScreenCoordinatesToRay(Vector.New(0.5,0.5,0))<br>
 
Space.Log("Direction "..ray.Direction.ToString())
 
Space.Log("Direction "..ray.Direction.ToString())
}}
+
|6=<pre>  --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)  </pre>}}
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 04:39, 14 July 2021

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)