wiki.sine.space | sinespace

Difference between revisions of "Scripting/SInput"

From wiki.sine.space
Jump to: navigation, search
m
(Replaced content with "#REDIRECT [https://docs.sine.space/v/scripting/client-scripting/viewer/sinput]")
Line 1: Line 1:
The SInput class returns the current state of input devices connected to the players device.
+
#REDIRECT [https://docs.sine.space/v/scripting/client-scripting/viewer/sinput]
 
+
==Keys==
+
To ensure a cross-platform experience that works with Game Pads, Keyboards, Mouse and Mobile devices - as well as foreign language keyboards, we do not allow you to listen for specific keyboard keys, instead you may listen to predefined key groups which are consistent across devices. These can be used where ever a function argument is named 'key'.
+
 
+
Keys
+
* Jump (usually spacebar)
+
* Fly (usually f)
+
* Run (usually left shift)
+
* Submit (usually return key)
+
* Cancel (usually escape)
+
* Tab Horiz (usually tab key)
+
* Tab Vert (gamepad only)
+
 
+
==Members==
+
{{ScriptFunction|bool|GetKeyDown|(string key);|Returns true if 'key' was pressed during this frame. |5=<pre>thisGameObject = Space.Host.ExecutingObject
+
 
+
OnUpdate = function()
+
  if Space.Input.GetKeyDown("space") then
+
Space.Log("Jump Key Down")
+
  end
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate) </pre> }}
+
 
+
{{ScriptFunction|bool|GetKey|(string key);|Returns true if 'key' is being held pressed. |5=<pre>thisGameObject = Space.Host.ExecutingObject
+
 
+
OnUpdate = function()
+
  if Space.Input.GetKey("space") then
+
Space.Log("Jump Key Held")
+
  end
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre> }}
+
 
+
{{ScriptFunction|bool|GetKeyUp|(string key);|Returns true if 'key' is no longer pressed during this frame (but was in the last). |5=<pre>thisGameObject = Space.Host.ExecutingObject
+
 
+
OnUpdate = function()
+
  if Space.Input.GetKeyUp("space") then
+
Space.Log("Jump Key Released")
+
  end
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre> }}
+
 
+
{{ScriptFunction|bool|GetMouseDown|(int button);|Returns true if mouse 'button' was pressed during this frame. |5=<pre>if Space.Input.GetMouseDown(1) then
+
  Space.Log("Right Mouse button pressed in this frame")
+
end</pre>| 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.OnUpdate(OnUpdate)  </pre> }}
+
 
+
{{ScriptFunction|bool|GetMouseHold|(int button);|Returns true if mouse 'button' is being held pressed.|5=<pre>if Space.Input.GetMouseHold(1) then
+
  Space.Log("Right Mouse button being held")
+
end</pre> |6= <pre>  --this script will make this object will follow your ovement while holding right click
+
--(Example: dragging objects to move )
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
OnUpdate = function()
+
  if Space.Input.GetMouseHold(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.OnUpdate(OnUpdate)  </pre> }}
+
 
+
{{ScriptFunction|bool|GetMouseUp|(int button);|Returns true if mouse 'button' is no longer pressed during this frame (but was in the last).|5=<pre>if Space.Input.GetMouseUp(1) then
+
  Space.Log("Right Mouse button was just unpressed")
+
end</pre>}}
+
 
+
{{ScriptFunction|void|Vibrate|(float intensity, float duration, bool leftHand);| Vibrates the controller (or phone, or gamepad) if a rumble device is present.
+
intensity: intensity from 0 to 1.0, duration: duration max 1.0 sec, leftHand, if true Rumble on the left hand, if false rumble on right hand, where applicable.|5=<pre>Space.Input.Vibrate(1,1,false)</pre>}}
+
 
+
 
+
==Properties==
+
 
+
{{ScriptFunction|float|ScrollWheel|{ get; }|Returns a non-0 value if the mouse wheel is being scrolled, value usually ranges from -1 to 1|5=<pre>if Space.Input.ScrollWheel> 0 then
+
Space.Log("mouse wheel is being scrolled up")
+
end</pre> |6= <pre> --this object is going to listen to your scroll wheel movement and move accordingly
+
--(Example: Custom controls on a minigame/interactive object)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnUpdate = function()
+
thisGameObject.WorldPosition = thisGameObject.WorldPosition + (thisGameObject.Up * Space.Input.ScrollWheel)
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)  </pre>}}
+
 
+
{{ScriptFunction|SVector|MousePosition|{ get; }|Returns the current position of the mouse in screen pixels. If on a touch screen device, this will also return the location of the first finger being pressed.|5=<pre>currentMousePos = Space.Input.MousePosition</pre> |6= <pre>    --this script will make this object will follow your ovement while holding right click
+
--(Example: dragging objects to move )
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
OnUpdate = function()
+
  if Space.Input.GetMouseHold(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.OnUpdate(OnUpdate)  </pre>}}
+
 
+
{{ScriptFunction|float|MouseX|{ get; }|Returns a float representing the Mouse/Right Joystick horizontal movement. If the value is positive the movement is upwards. If the value is negative the movement is downwards. The value is derived by multiplying mouse delta with axis sensitivity. This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value. |5=<pre>MouseX = Space.Input.MouseX</pre>
+
|6=
+
<pre>
+
--the below script will rotate this object along the Y axis
+
--according to your mouse/right joystick horizontal movement
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
function OnUpdate()
+
currentY = thisGameObject.WorldRotation.EulerAngles.Y
+
newY = currentY + Space.Input.MouseX
+
thisGameObject.WorldRotation = Quaternion.Euler(0, newY, 0)
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate) </pre> }}
+
 
+
{{ScriptFunction|float|MouseY|{ get; }|Returns a float representing the Mouse/Right Joystick vertical movement. If the value is positive the movement is to the right. If the value is negative the movement is to the left. The value is derived by multiplying mouse delta with axis sensitivity. This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value. |5=<pre>MouseY = Space.Input.MouseY</pre>
+
|6=
+
<pre>
+
--the below script will rotate this object along the Y axis
+
--according to your mouse/right joystick vertical movement
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
function OnUpdate()
+
currentX = thisGameObject.WorldRotation.EulerAngles.X
+
newX = currentY + Space.Input.MouseY
+
thisGameObject.WorldRotation = Quaternion.Euler(newX , 0, 0)
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate) </pre> }}
+
 
+
 
+
{{ScriptFunction|SVector|MovementAxis|{ get; }|Returns left/right (A/D) movement on X, forward/back (W/S) on Y, and up/down (E/C) on Z|5=<pre>moveAxis  = Space.Input.MovementAxis</pre> |6= <pre>  --this object is going to listen to your A/D key presses and move accordingly
+
--(Example: Custom controls on a minigame)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnUpdate = function()
+
if Space.Input.MovementAxis.Y > 0 then
+
            thisGameObject.WorldPosition = thisGameObject.WorldPosition + thisGameObject.Forward
+
            elseif Space.Input.MovementAxis.Y < 0 then 
+
            thisGameObject.WorldPosition = thisGameObject.WorldPosition - thisGameObject.Forward
+
            end
+
           
+
            if Space.Input.MovementAxis.X > 0 then
+
            thisGameObject.WorldPosition = thisGameObject.WorldPosition + thisGameObject.Right
+
            elseif Space.Input.MovementAxis.X < 0 then 
+
            thisGameObject.WorldPosition = thisGameObject.WorldPosition - thisGameObject.Right
+
            end
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)  </pre>}}
+
 
+
{{ScriptFunction|bool|ClickToWalk|{ get; set; }|Enable or disable Click To Walk feature which allows movement of avatar by clicking the ground.|5= <pre>Space.Input.ClickToWalk = true</pre>|6=<pre>--Make an object toggle Click To Walk when clicked
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
OnClick = function()
+
Space.Input.ClickToWalk = not Space.Input.ClickToWalk
+
end
+
 
+
 
+
thisGameObject.AddClickable()
+
thisGameObject.Clickable.OnClick(OnClick)</pre>}}
+
 
+
{{ScriptFunction|bool|AltFire|{ get; }|Return true if alternative fire is pressed (Mouselook Mode)|5= <pre>if Space.Input.AltFire == true then
+
  Space.Log("AltFire pressed")
+
end</pre>|6=<pre>--Create a GameObject from resource when Alternate Fire button is pressed
+
--(Example: spawn a bullet)
+
--[Add resource "bullet" as a resource in scripting runtime component]
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
bullet = Space.GetResource("bullet")
+
 
+
 
+
 
+
OnUpdate = function()
+
  if Space.Input.AltFire then
+
  Space.Scene.CreateGameObject(bullet)
+
  end
+
end
+
 
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre>}}
+
 
+
{{ScriptFunction|bool|Fire|{ get; }|Return true if primary fire is pressed (Mouselook Mode)|5= <pre>if Space.Input.Fire == true then
+
  Space.Log("Fire pressed")
+
end</pre>|6=<pre>--Create a GameObject from resource when Primary Fire button is pressed
+
--(Example: spawn a bullet)
+
--[Add resource "bullet" as a resource in scripting runtime component]
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
bullet = Space.GetResource("bullet")
+
 
+
 
+
 
+
OnUpdate = function()
+
  if Space.Input.Fire then
+
  Space.Scene.CreateGameObject(bullet)
+
  end
+
end
+
 
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre>}}
+
 
+
{{ScriptFunction|bool|IsVRActive|{ get; }|Returns true if VR is active|5= <pre>if Space.Input.IsVRActive == true then
+
  Space.Log("VR is active")
+
end</pre>}}
+
 
+
{{ScriptFunction|bool|IsVRAvailable|{ get; }|Returns true if VR is available|5= <pre>if Space.Input.IsVRAvailable == true then
+
  Space.Log("VR is available")
+
end</pre>}}
+
 
+
{{ScriptFunction|bool|MouseLook|{ get;set; }|Enable or disable Mouse Look feature|5= <pre>Space.Input.MouseLook = true</pre>|6=<pre>
+
--the below script will put your player into MouseLook mode if you are near the object
+
--and return you to normal mode if you are far from the object
+
--(example: entering an area/experience where MouseLook is required/mandatory)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
function OnUpdate()
+
  positionAvatar = Space.Scene.PlayerAvatar.GameObject.WorldPosition
+
  positionObject = thisGameObject.WorldPosition
+
 
+
    if positionAvatar.InRange(positionObject, 5.0) then
+
          if Space.Input.MouseLook == false then
+
            Space.Input.MouseLook = true
+
          end
+
      else
+
          if Space.Input.MouseLook == true then
+
            Space.Input.MouseLook = false
+
          end
+
      end
+
 
+
end 
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre>}}
+
 
+
{{ScriptFunction|bool|CursorInUI|{ get; }|Returns true if the cursor is over the Sinespace UI|5= <pre>turnAxis = Space.Input.CursorInUI</pre>|6=<pre> --this object is going to listen to your scroll wheel movement and move accordingly
+
--UNLESS your cursor is on the sinespace UI
+
--(Example: Scrolling chat won't also move the object)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
OnUpdate = function()
+
    if Space.Input.CursorInUI == false then
+
    thisGameObject.WorldPosition = thisGameObject.WorldPosition + (thisGameObject.Up * Space.Input.ScrollWheel)
+
    end
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)  </pre>}}
+
 
+
{{ScriptFunction|SVector|TurnAxis|{ get; }|Returns the Turn Axis (-1 to 1 on Vector's X value)|5= <pre>turnAxis = Space.Input.TurnAxis</pre>|6=<pre>--makes this object color red if player is turning left
+
--and color green if player is turning right
+
--and blue if player is not turning
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
OnUpdate = function()
+
  if Space.Input.TurnAxis.X > 0 then
+
    thisGameObject.Renderer.Material.SetColor("_Color",Color.Red)
+
  elseif Space.Input.TurnAxis.X < 0 then
+
    thisGameObject.Renderer.Material.SetColor("_Color",Color.Green)
+
  elseif Space.Input.TurnAxis.X == 0 then
+
    thisGameObject.Renderer.Material.SetColor("_Color",Color.Blue)
+
  end
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre>}}
+
 
+
{{ScriptFunction|SVector|VRLeftControllerPosition|{ get; }|Returns position of Left VR Controller|5= <pre>posVRleft = Space.Input.VRLeftControllerPosition</pre>}}
+
 
+
{{ScriptFunction|SQuaternion|VRLeftControllerRotation|{ get; }|Return rotation of Left VR Controller|5= <pre>rotVRleft = Space.Input.VRLeftControllerRotation</pre>}}
+
 
+
{{ScriptFunction|SVector|VRRightControllerPosition|{ get; }|Returns position of Right VR Controller|5= <pre>posVRright = Space.Input.VRRightControllerPosition</pre>}}
+
 
+
{{ScriptFunction|SQuaternion|VRRightControllerRotation|{ get; }|Return rotation of Right VR Controller|5= <pre>rotVRright = Space.Input.VRRightControllerRotation</pre>}}
+
 
+
 
+
{{Scripting Navbox}}
+

Revision as of 04:54, 19 September 2022

  1. REDIRECT [1]