Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add angle to camera lagging effect #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 48 additions & 17 deletions Assets/Prefabs/Main Camera.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ GameObject:
serializedVersion: 4
m_Component:
- 4: {fileID: 4000012287847772}
- 20: {fileID: 20000013792283148}
- 92: {fileID: 92000012303783254}
- 124: {fileID: 124000014213847278}
- 81: {fileID: 81000011828737924}
- 114: {fileID: 114000010170162926}
- 114: {fileID: 114000011411732050}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand All @@ -48,6 +43,39 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1000014010881316
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 4: {fileID: 4000010351402194}
- 20: {fileID: 20000013621435608}
- 92: {fileID: 92000012462703292}
- 124: {fileID: 124000014206834730}
- 81: {fileID: 81000014010250770}
- 114: {fileID: 114000013629650414}
m_Layer: 0
m_Name: Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4000010351402194
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000014010881316}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -12}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 4000012287847772}
m_RootOrder: 1
--- !u!4 &4000011621508258
Transform:
m_ObjectHideFlags: 1
Expand All @@ -68,23 +96,24 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000012717703722}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 6, z: -12}
m_LocalPosition: {x: 0, y: 6, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 4000011621508258}
- {fileID: 4000010351402194}
m_Father: {fileID: 0}
m_RootOrder: 0
--- !u!20 &20000013792283148
--- !u!20 &20000013621435608
Camera:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000012717703722}
m_GameObject: {fileID: 1000014010881316}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.09754437, g: 0.07266436, b: 0.11764705, a: 0}
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
Expand All @@ -109,19 +138,19 @@ Camera:
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!81 &81000011828737924
--- !u!81 &81000014010250770
AudioListener:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000012717703722}
m_GameObject: {fileID: 1000014010881316}
m_Enabled: 1
--- !u!92 &92000012303783254
--- !u!92 &92000012462703292
Behaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000012717703722}
m_GameObject: {fileID: 1000014010881316}
m_Enabled: 1
--- !u!108 &108000014290524078
Light:
Expand Down Expand Up @@ -172,12 +201,14 @@ MonoBehaviour:
cameraHeightThresholdPercent: 0.75
minX: 0
maxX: Infinity
--- !u!114 &114000011411732050
maxRotationOffset: {x: 7, y: 3}
rotationTranslationalDifferenceTarget: {x: 7, y: 5}
--- !u!114 &114000013629650414
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000012717703722}
m_GameObject: {fileID: 1000014010881316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7fceaeb339b971b429c4cc600acabd13, type: 3}
Expand Down Expand Up @@ -210,10 +241,10 @@ MonoBehaviour:
blurAndFlaresShader: {fileID: 4800000, guid: be6e39cf196f146d5be72fbefb18ed75, type: 3}
brightPassFilterShader: {fileID: 4800000, guid: 0aeaa4cb29f5d4e9c8455f04c8575c8c,
type: 3}
--- !u!124 &124000014213847278
--- !u!124 &124000014206834730
Behaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1000012717703722}
m_GameObject: {fileID: 1000014010881316}
m_Enabled: 1
18 changes: 9 additions & 9 deletions Assets/Scenes/level1.unity
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ Prefab:
type: 2}
propertyPath: m_CurrentCamera
value:
objectReference: {fileID: 2118262561}
objectReference: {fileID: 1556632846}
- target: {fileID: 114000014221196914, guid: 57186ba0bd02e734da4975f137272c80,
type: 2}
propertyPath: m_ShowSamples
Expand All @@ -567,7 +567,7 @@ Prefab:
type: 2}
propertyPath: m_Cameras.Array.data[0]
value:
objectReference: {fileID: 2118262561}
objectReference: {fileID: 1556632846}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 57186ba0bd02e734da4975f137272c80, type: 2}
m_IsPrefabParent: 0
Expand Down Expand Up @@ -975,7 +975,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4000012287847772, guid: fd625f62714184d45ae0001687d6072d, type: 2}
propertyPath: m_LocalPosition.z
value: -12
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000012287847772, guid: fd625f62714184d45ae0001687d6072d, type: 2}
propertyPath: m_LocalRotation.x
Expand Down Expand Up @@ -1642,6 +1642,11 @@ Prefab:
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 51f34108d6e38fb4bb18af318965cefb, type: 2}
m_IsPrefabParent: 0
--- !u!20 &1556632846 stripped
Camera:
m_PrefabParentObject: {fileID: 20000013621435608, guid: fd625f62714184d45ae0001687d6072d,
type: 2}
m_PrefabInternal: {fileID: 874214590}
--- !u!1 &1567273262
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1868,7 +1873,7 @@ Prefab:
type: 2}
propertyPath: m_Camera
value:
objectReference: {fileID: 2118262561}
objectReference: {fileID: 0}
- target: {fileID: 114000013732220262, guid: cb43706faeb9aa547a06f87393f8b2f7,
type: 2}
propertyPath: volumeCurve.m_Curve.Array.data[1].time
Expand Down Expand Up @@ -2233,8 +2238,3 @@ Prefab:
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 51f34108d6e38fb4bb18af318965cefb, type: 2}
m_IsPrefabParent: 0
--- !u!20 &2118262561 stripped
Camera:
m_PrefabParentObject: {fileID: 20000013792283148, guid: fd625f62714184d45ae0001687d6072d,
type: 2}
m_PrefabInternal: {fileID: 874214590}
14 changes: 14 additions & 0 deletions Assets/Scripts/Player/CameraFollow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class CameraFollow : MonoBehaviour {
[Tooltip("Right-most camera position")]
private float maxX;

[SerializeField]
private Vector2 maxRotationOffset;
[SerializeField]
[Tooltip("How much translational difference is required to reach max rotational offset on x and y")]
private Vector2 rotationTranslationalDifferenceTarget;

// Use this for initialization
void Start () {
Debug.Assert(target != null);
Expand Down Expand Up @@ -69,5 +75,13 @@ void Update () {
}

this.transform.position = position;


Vector3 rotation = this.transform.eulerAngles;
Vector3 diff = target.position - this.transform.position;

rotation.y = Mathf.Clamp(diff.x / this.rotationTranslationalDifferenceTarget.x, -1, 1) * maxRotationOffset.x;
rotation.x = -Mathf.Clamp(diff.y / this.rotationTranslationalDifferenceTarget.y, -1, 1) * maxRotationOffset.y;
this.transform.eulerAngles = rotation;
}
}