Commit 907cfe35 authored by Tommé Nöll's avatar Tommé Nöll
Browse files

Camera follows player

parent ae773752
......@@ -103,6 +103,7 @@ GameObject:
- component: {fileID: 8811539149977030265}
- component: {fileID: 8811539149977030264}
- component: {fileID: 8811539149977030271}
- component: {fileID: 4797791628540356424}
m_Layer: 0
m_Name: MainCamera
m_TagString: MainCamera
......@@ -220,3 +221,17 @@ MonoBehaviour:
corruptionMap: {fileID: 0}
showCorruptionMap: 0
applyPostEffect: 0
--- !u!114 &4797791628540356424
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8811539149977030262}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d6ee6543f1584fbd8abb93bb2e56db5b, type: 3}
m_Name:
m_EditorClassIdentifier:
player: {fileID: 0}
offset: {x: 0, y: 0, z: -10}
......@@ -1608,18 +1608,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 4809852221727672545}
m_PrefabAsset: {fileID: 0}
--- !u!114 &576296497 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1547779244, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
m_PrefabInstance: {fileID: 1202668657}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eff681ef17b34b34e8e2ad0af641fa6d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &636887936 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2554834490484476826, guid: 7ef06ffc179d97098a6c30d5f8570a4e,
......@@ -2805,7 +2793,7 @@ Transform:
m_LocalScale: {x: 61.23308, y: 1.12896, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1202668657
PrefabInstance:
......@@ -2814,6 +2802,16 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 8849362558915370004, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8849362558915370004, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_TagString
value: Player
objectReference: {fileID: 0}
- target: {fileID: 264577551908436831, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Name
......@@ -2930,6 +2928,21 @@ PrefabInstance:
propertyPath: m_Size.y
value: 1.22
objectReference: {fileID: 0}
- target: {fileID: 3724751736021467387, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3724751736021467387, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.5
objectReference: {fileID: 0}
- target: {fileID: 3724751736021467387, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_LocalPosition.x
value: -2.56
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a1e0107a2375e1140a669c1da0647f9a, type: 3}
--- !u!1001 &1206557182
......@@ -3151,6 +3164,40 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1269226550}
m_PrefabAsset: {fileID: 0}
--- !u!84 &1294983772
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 1181
m_Height: 559
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &1300473122
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -3970,40 +4017,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1551787235}
m_PrefabAsset: {fileID: 0}
--- !u!84 &1570133119
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 1181
m_Height: 559
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &1578749498
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -4352,12 +4365,12 @@ PrefabInstance:
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.x
value: 9.46
value: 11.02
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.81
value: 0.62
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
......@@ -5523,12 +5536,12 @@ PrefabInstance:
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.x
value: -21.25
value: 5.21
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.y
value: 1.58
value: 1.72
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
......@@ -5579,7 +5592,7 @@ PrefabInstance:
type: 3}
propertyPath: player
value:
objectReference: {fileID: 576296497}
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030271, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: corruptionMap
......@@ -5589,7 +5602,7 @@ PrefabInstance:
type: 3}
propertyPath: m_TargetTexture
value:
objectReference: {fileID: 1570133119}
objectReference: {fileID: 1294983772}
- target: {fileID: 8811539148413200140, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: corruptionMap
......
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
[HideInInspector] public Player player;
[SerializeField] private Vector3 offset;
/*[Range(0, 1)]
[SerializeField] private float panSpeed = 1.0f;
[Header("Lookahead")]
[SerializeField] private float lookaheadDistance = 10.0f;
[SerializeField] private float lookaheadDelay = 5.0f;
[SerializeField] private float resetLookaheadDelay = 5.0f;
[SerializeField] private float lookAheadSpeedMultiplier = 0.1f;
private float playerMovingTime;*/
private Vector3 lastPlayerPosition;
// Start is called before the first frame update
void Start()
{
try
{
FindPlayer();
}
catch(NullReferenceException e)
{
Debug.LogError("No Player found in Scene", this);
return;
}
SnapToPlayer();
}
public void FindPlayer()
{
player = GameObject.FindWithTag("Player").GetComponent<Player>();
}
public void SnapToPlayer()
{
transform.position = player.transform.position + offset;
lastPlayerPosition = player.transform.position;
}
private void ApplyPlayerMovement()
{
transform.position += player.transform.position - lastPlayerPosition;
lastPlayerPosition = player.transform.position;
}
void LateUpdate()
{
if (!player)
{
return;
}
ApplyPlayerMovement();
}
}
fileFormatVersion: 2
guid: d6ee6543f1584fbd8abb93bb2e56db5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment