Camera Edges Unity Asset
It Allows you to get and move any camera (screen) edge position in world space with a single line of code.
want to detect when objects leave screen ?
simply write:
if ( bulletPosition . x > camera . Get Top Right ( desiredZDistance ) .x )
it's as simple as that.
want to detect when objects leave screen ?
simply write:
if ( bulletPosition . x > camera . Get Top Right ( desiredZDistance ) .x )
it's as simple as that.
Demo Video
Tutorial Video
Documentation
The Asset has two main set of methods:
1. camera.Get...()
2. camera.Move...()
- it also has two utility methods
1. camera.GetSizeInWorldSpace()
2. camera.GetDistance()
1. camera.Get...()
2. camera.Move...()
- it also has two utility methods
1. camera.GetSizeInWorldSpace()
2. camera.GetDistance()
Camera.Get...()
- method signature
Vector3 Get (float desiredZDistanceFromCamera)
- you can get any camera pivot, for example:
Vector3 screenTopLeft = myCamera.GetTopLeft( desiredZDistanceFromCamera );
parameters:
- it returns the screen edge in world space as vector 3
- it accepts a float that represents the desired z distance from camera.
(the desired z distance from camera is explained below)
Note: for 2D (orthographic) cameras, you can simply use any value for desired distance from camera (like 10) if your camera is not rotated.
- methods list
camera.GetTopLeft( desiredZDistanceFromCamera)
camera.GetTopPosition( desiredZDistanceFromCamera)
camera.GetTopRight( desiredZDistanceFromCamera)
camera.GetLeftPosition( desiredZDistanceFromCamera)
camera.GetCenter( desiredZDistanceFromCamera)
camera.GetRightPosition( desiredZDistanceFromCamera)
camera.GetBottomLeft( desiredZDistanceFromCamera)
camera.GetBottomPosition( desiredZDistanceFromCamera)
camera.GetBottomRight( desiredZDistanceFromCamera)
Vector3 Get (float desiredZDistanceFromCamera)
- you can get any camera pivot, for example:
Vector3 screenTopLeft = myCamera.GetTopLeft( desiredZDistanceFromCamera );
parameters:
- it returns the screen edge in world space as vector 3
- it accepts a float that represents the desired z distance from camera.
(the desired z distance from camera is explained below)
Note: for 2D (orthographic) cameras, you can simply use any value for desired distance from camera (like 10) if your camera is not rotated.
- methods list
camera.GetTopLeft( desiredZDistanceFromCamera)
camera.GetTopPosition( desiredZDistanceFromCamera)
camera.GetTopRight( desiredZDistanceFromCamera)
camera.GetLeftPosition( desiredZDistanceFromCamera)
camera.GetCenter( desiredZDistanceFromCamera)
camera.GetRightPosition( desiredZDistanceFromCamera)
camera.GetBottomLeft( desiredZDistanceFromCamera)
camera.GetBottomPosition( desiredZDistanceFromCamera)
camera.GetBottomRight( desiredZDistanceFromCamera)
Camera.Move ...()
method has two signatures:
Vector3 Move... ( Vector3 targetPosition, float desiredZDistanceFromCamera)
Vector3 Move...( Vector3 targetPosition, float desiredZDistance, GameObject topParent)
usage:
it moves the camera to a specific position, using any camera pivot, for example, to move the camera top left to the start position, simply call:
camera.MoveTopLeft ( targetPosition, desiredZDistanceFromCamera)
- you can pass an optional top parent parameter, to move the entire parent of the camera, instead of the camera game object itself (for example, if the camera is a child of the player game object and you want to move the entire player with the camera)
parameters:
- it accepts the target position as Vector3
- it accepts the desired z distance from camera as float
- it accepts an optional top parent parameter as GameObject
- it returns the offset the camera moved as Vector3
Methods List:
camera.MoveTopLeft
camera.MoveTopCenterTo
camera.MoveTopRight
camera.MoveLeftCenterTo
camera.MoveCenterTo
camera.MoveRightCenterTo
camera.MoveBottomLeftTo
camera.MoveBottomCenterTo
camera.MoveBottomRightTo
Vector3 Move... ( Vector3 targetPosition, float desiredZDistanceFromCamera)
Vector3 Move...( Vector3 targetPosition, float desiredZDistance, GameObject topParent)
usage:
it moves the camera to a specific position, using any camera pivot, for example, to move the camera top left to the start position, simply call:
camera.MoveTopLeft ( targetPosition, desiredZDistanceFromCamera)
- you can pass an optional top parent parameter, to move the entire parent of the camera, instead of the camera game object itself (for example, if the camera is a child of the player game object and you want to move the entire player with the camera)
parameters:
- it accepts the target position as Vector3
- it accepts the desired z distance from camera as float
- it accepts an optional top parent parameter as GameObject
- it returns the offset the camera moved as Vector3
Methods List:
camera.MoveTopLeft
camera.MoveTopCenterTo
camera.MoveTopRight
camera.MoveLeftCenterTo
camera.MoveCenterTo
camera.MoveRightCenterTo
camera.MoveBottomLeftTo
camera.MoveBottomCenterTo
camera.MoveBottomRightTo
Camera.GetSizeInWorldSpace()
signature:
Vector2 GetSizeInWorldSpace ( desiredZDistanceFromCamera )
usage:
it returns the camera frustum size in world space
Vector2 cameraSize = camera.GetSizeInWorldSpace ( desiredZDistanceFromCamera )
Parameters:
- accepts the desired z distance from camera as a float
- returns the camera size in world space as Vector2
Vector2 GetSizeInWorldSpace ( desiredZDistanceFromCamera )
usage:
it returns the camera frustum size in world space
Vector2 cameraSize = camera.GetSizeInWorldSpace ( desiredZDistanceFromCamera )
Parameters:
- accepts the desired z distance from camera as a float
- returns the camera size in world space as Vector2
Camera.GetDistance()
has 2 Signatures:
float GetDistance (Transform targetObject)
float GetDistance (Vector3 targetPosition)
Usage:
it returns the z distance from an object to the camera, the returned value can be used in the other get & move methods, for example, if you want to get the camera top left position at the player plane, simply write:
float zDistanceToPlayer = camera.GetDistance ( playerTransform );
Vector3 topLeft = camera.GetTopLeft( zDistanceToPlayer );
parameters:
- it accepts a target Transorm, or position as vector3.
- it returns the z distance from camera as a float
float GetDistance (Transform targetObject)
float GetDistance (Vector3 targetPosition)
Usage:
it returns the z distance from an object to the camera, the returned value can be used in the other get & move methods, for example, if you want to get the camera top left position at the player plane, simply write:
float zDistanceToPlayer = camera.GetDistance ( playerTransform );
Vector3 topLeft = camera.GetTopLeft( zDistanceToPlayer );
parameters:
- it accepts a target Transorm, or position as vector3.
- it returns the z distance from camera as a float
Understanding Desired Distance From Camera
since the camera frustum is 3D, it has infinite edges (top left & top right points) & infinite sizes depending on how far the frustum slice is from the camera.
- to determine the exact point you want, you need to use the desired z distance from camera parameter
- which determines the desired slice of the camera frustum that you want to get or move.
- watch the above tutorial if you are finding this hard to grasp ;) .
- to get edges of 2D orthographic non-rotated cameras, you can simply use 10 for the distance from camera ( since their frustum has the same size at any distance from the camera )
- if you want to work with the exact slice of the camera frustum that contains the player or bullet, use the GetDistance() method, documented above.
- Keep in mind that calling camera.Move...() moves the camera in x,y and z axis as well
- to determine the exact point you want, you need to use the desired z distance from camera parameter
- which determines the desired slice of the camera frustum that you want to get or move.
- watch the above tutorial if you are finding this hard to grasp ;) .
- to get edges of 2D orthographic non-rotated cameras, you can simply use 10 for the distance from camera ( since their frustum has the same size at any distance from the camera )
- if you want to work with the exact slice of the camera frustum that contains the player or bullet, use the GetDistance() method, documented above.
- Keep in mind that calling camera.Move...() moves the camera in x,y and z axis as well
Love it ? Then you will love Object Edges 2D Asset
Asset Store URL: https://www.assetstore.unity3d.com/#!/content/66285
2. Directional Zoom
Zoom only in the direction you want
Asset Page
Asset Page