wiki.sine.space | sinespace

Difference between revisions of "Scripting/SCameraManager"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/scameramanager")
 
Line 1: Line 1:
The SCameraManager class allows you to take and manipulate the users camera. Combine with [[Scripting/SCamera]] to create 2D side-scrolling regions!
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/scameramanager
 
+
==Members==
+
{{ScriptFunction|bool|IsLocked|{ get; }|Returns true if the Camera is locked and can be manipulated by this script.|5=
+
obj = Space.Host.ExecutingObject;<br><br>
+
Space.Camera.LockCamera (obj); <br>
+
Space.Log(Space.Camera.IsLocked); <br>
+
''--prints "True" to the console''}}
+
 
+
{{ScriptFunction|void|ReleaseCamera|();|Relinquishes control of the Camera back to Space| 5=
+
obj = Space.Host.ExecutingObject;<br><br>
+
 
+
''-- Let's lock the camera for a moment''<br>
+
Space.Camera.LockCamera (obj);<br>
+
''-- Now we can release it''<br>
+
if Space.Camera.IsLocked then<br>
+
:Space.Camera.ReleaseCamera ();<br>
+
:Space.Log("Camera released");<br>
+
end}}
+
 
+
{{ScriptFunction|void|LockCamera|(SGameObject owner);|Takes control of the Camera as long as 'owner' exists in the scene, or until ReleaseCamera() has been called. Using the Host runtime as the owner is often a good practice.|5=
+
obj = Space.Host.ExecutingObject;<br><br>
+
Space.Camera.LockCamera (obj);<br>
+
''-- If no camera position/orientation is set upon locking, the camera will lock on the avatar.''}}
+
 
+
{{ScriptFunction|void|SetCameraPositionOrientation|(SVector position, SQuaternion orientation);|Forces the camera to be at position facing orientation for the frame. Needs to be called every frame.|5=
+
obj = Space.Host.ExecutingObject;<br>
+
local VectorPos = Vector.New(0,0,0);<br>
+
local VectorRot = Quaternion.Euler(-60,0,0);<br><br>
+
Space.Camera.LockCamera (obj);<br>
+
Space.Camera.SetCameraPositionOrientation (VectorPos,VectorRot);<br>
+
''-- Now the camera is positioned at the global origin and is facing the sky at 60 degrees.''
+
}}
+
 
+
 
+
{{ScriptFunction|SRay|ScreenCoordinatesToRay|(SVector screenCoordinates);|Returns a ray going from camera through a screen point.|5=
+
obj = Space.Host.ExecutingObject;<br>
+
local cameraRay = Space.Camera.ScreenCoordinatesToRay (Vector.New(0,50,0));<br><br>
+
Space.Log(cameraRay.Origin);<br>
+
Space.Log(cameraRay.Direction);<br>
+
''-- 2 vectors (location of the ray origin (somewhere close to camera coordinates) and direction of the ray towards the point at (0,50,0)) are printed to the console.''<br>
+
|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|SGameObject|MainCamera|;|Note, this property is generally read-only. It's position is driven by internal code.|5=
+
obj = Space.Host.ExecutingObject;<br>
+
Space.Log(Space.Camera.MainCamera.Name); <br>
+
''--print "Main Camera" to the console.''}}
+
 
+
{{ScriptFunction|SGameObject|ActiveVirtualCamera|;|Get the currently active Cinemachine Virtual Camera game object.|5=
+
obj = Space.Host.ExecutingObject;<br>
+
Space.Log(Space.Camera.ActiveVirtualCamera.Name); <br>
+
''--print "Virtual PlayerCamera" to the console.''}}
+
 
+
{{ScriptFunction|SVector|ScreenCoordinatesToWorld|(SVector screenCoordinates);|Transforms a point from screen space into world space.|5=
+
obj = Space.Host.ExecutingObject;<br>
+
Space.Log(Space.Camera.ScreenCoordinatesToWorld(Vector.New(0.5,0.5,0)).ToString());<br><br>
+
''-- Print 3 worldspace vectors created by screen space point to the console.''<br>
+
}}
+
 
+
 
+
{{ScriptFunction|SVector|WorldCoordinatesToScreen|(SVector coordinates);|Transforms position from world space into screen space.|5=
+
local trans = Space.Host.ExecutingObject;<br>
+
Space.Log(Space.Camera.WorldCoordinatesToScreen(trans.WorldPosition).ToString());<br><br>
+
''-- Print the position created by world space point to the console.''<br>
+
}}
+
 
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:22, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/scameramanager