wiki.sine.space | sinespace

Difference between revisions of "Scripting/SCameraManager"

From wiki.sine.space
Jump to: navigation, search
m
Line 42: Line 42:
 
}}
 
}}
  
 +
{{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}}
 
{{Scripting Navbox}}

Revision as of 02:55, 15 December 2020

The SCameraManager class allows you to take and manipulate the users camera. Combine with Scripting/SCamera to create 2D side-scrolling regions!

Members

IsLocked

bool IsLocked { get; }

Returns true if the Camera is locked and can be manipulated by this script.

obj = Space.Host.ExecutingObject;

Space.Camera.LockCamera (obj);
Space.Log(Space.Camera.IsLocked);

--prints "True" to the console


ReleaseCamera

void ReleaseCamera ();

Relinquishes control of the Camera back to Space

obj = Space.Host.ExecutingObject;

-- Let's lock the camera for a moment
Space.Camera.LockCamera (obj);
-- Now we can release it
if Space.Camera.IsLocked then

Space.Camera.ReleaseCamera ();
Space.Log("Camera released");
end


LockCamera

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.

obj = Space.Host.ExecutingObject;

Space.Camera.LockCamera (obj);

-- If no camera position/orientation is set upon locking, the camera will lock on the avatar.


SetCameraPositionOrientation

void SetCameraPositionOrientation (SVector position, SQuaternion orientation);

Forces the camera to be at position facing orientation for the frame. Needs to be called every frame.

obj = Space.Host.ExecutingObject;

local VectorPos = Vector.New(0,0,0);
local VectorRot = Quaternion.Euler(-60,0,0);

Space.Camera.LockCamera (obj);
Space.Camera.SetCameraPositionOrientation (VectorPos,VectorRot);

-- Now the camera is positioned at the global origin and is facing the sky at 60 degrees.



ScreenCoordinatesToRay

SRay ScreenCoordinatesToRay (SVector screenCoordinates);

Returns a ray going from camera through a screen point.

obj = Space.Host.ExecutingObject;

local cameraRay = Space.Camera.ScreenCoordinatesToRay (Vector.New(0,50,0));

Space.Log(cameraRay.Origin);
Space.Log(cameraRay.Direction);

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


MainCamera

SGameObject MainCamera ;

Note, this property is generally read-only. It's position is driven by internal code.

obj = Space.Host.ExecutingObject;

Space.Log(Space.Camera.MainCamera.Name);

--print "Main Camera" to the console.


ActiveVirtualCamera

SGameObject ActiveVirtualCamera ;

Get the currently active Cinemachine Virtual Camera game object.

obj = Space.Host.ExecutingObject;

Space.Log(Space.Camera.ActiveVirtualCamera.Name);

--print "Virtual PlayerCamera" to the console.


ScreenCoordinatesToWorld

SVector ScreenCoordinatesToWorld (SVector screenCoordinates);

Transforms a point from screen space into world space.

obj = Space.Host.ExecutingObject;

Space.Log(Space.Camera.ScreenCoordinatesToWorld(Vector.New(0.5,0.5,0)).ToString());

-- Print 3 worldspace vectors created by screen space point to the console.



WorldCoordinatesToScreen

SVector WorldCoordinatesToScreen (SVector coordinates);

Transforms position from world space into screen space.

local trans = Space.Host.ExecutingObject;

Space.Log(Space.Camera.WorldCoordinatesToScreen(trans.WorldPosition).ToString());

-- Print the position created by world space point to the console.