Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Birb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gadig
Birb
Commits
6ddfd6ba
Commit
6ddfd6ba
authored
Feb 22, 2017
by
David Cooper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Second Attempt to merge a camera that smoothly follows a player
parent
36b87a7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
Assets/Scripts/Player/CameraFollow.cs
Assets/Scripts/Player/CameraFollow.cs
+66
-0
No files found.
Assets/Scripts/Player/CameraFollow.cs
0 → 100644
View file @
6ddfd6ba
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
CameraFollow
:
SingletonBehaviour
<
CameraFollow
>
{
Camera
cameraObj
;
public
float
smoothSpeed
;
private
float
MaxHeight
;
private
float
MaxWidth
;
private
float
MinHeight
;
private
float
MinWidth
;
private
float
OZ
;
// Use this for initialization
void
Start
()
{
cameraObj
=
Camera
.
main
;
float
camHeight
=
cameraObj
.
orthographicSize
*
2
;
float
camWidth
=
cameraObj
.
aspect
*
camHeight
;
MaxHeight
=
World
.
Height
-
camHeight
/
2
;
MaxWidth
=
World
.
Width
-
camWidth
/
2
;
MinHeight
=
World
.
Height
+
camHeight
/
2
;
MinWidth
=
World
.
Width
+
camHeight
/
2
;
OZ
=
cameraObj
.
transform
.
position
.
z
;
}
// Update is called once per frame
void
Update
()
{
Vector3
targetPOS
=
Vector3
.
Lerp
(
cameraObj
.
transform
.
position
,
transform
.
position
,
smoothSpeed
*
Time
.
deltaTime
);
/*
//camera dimensions and center
float camHeight = cameraObj.orthographicSize * 2;
float camWidth = cameraObj.aspect * camHeight;
if(targetPOS.y + camHeight > World.Height) //if camera is above bounds
{
targetPOS.y = (MaxHeight);
}
if(targetPOS.y - camHeight < World.Height) // if below bounds
{
targetPOS.y = (MinHeight);
}
if(targetPOS.x + camWidth > World.Width) //if right of bounds
{
targetPOS.x = (MaxWidth);
}
if(targetPOS.x - camWidth < World.Width) // if left of bounds
{
targetPOS.x = (MinWidth);
}*/
cameraObj
.
transform
.
position
=
new
Vector3
(
targetPOS
.
x
,
targetPOS
.
y
,
OZ
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment