Commit 14a68535 authored by Tommé Nöll's avatar Tommé Nöll
Browse files

Camera lookahead

parent 907cfe35
......@@ -235,3 +235,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
player: {fileID: 0}
offset: {x: 0, y: 0, z: -10}
panSpeed: 4
lookaheadDistance: 4
lookaheadDelay: 1
lookAheadSpeedMultiplier: 0.5
minSpeed: 0.05
......@@ -276,6 +276,40 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 78132087}
m_PrefabAsset: {fileID: 0}
--- !u!84 &78580244
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 &96193114
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -2790,7 +2824,7 @@ Transform:
m_GameObject: {fileID: 1163664074}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.095, y: -2.065, z: 0}
m_LocalScale: {x: 61.23308, y: 1.12896, z: 1}
m_LocalScale: {x: 200, y: 1.12896, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
......@@ -3164,40 +3198,6 @@ 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
......@@ -5602,11 +5602,16 @@ PrefabInstance:
type: 3}
propertyPath: m_TargetTexture
value:
objectReference: {fileID: 1294983772}
objectReference: {fileID: 78580244}
- target: {fileID: 8811539148413200140, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: corruptionMap
value:
objectReference: {fileID: 120497678}
- target: {fileID: 4797791628540356424, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: resetLookaheadDelay
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 388a7af523fdebaafad4a5d1ae1a896b, type: 3}
......@@ -7,15 +7,15 @@ public class CameraController : MonoBehaviour
{
[HideInInspector] public Player player;
[SerializeField] private Vector3 offset;
/*[Range(0, 1)]
[SerializeField] private float panSpeed = 1.0f;
[SerializeField] private float panSpeed = 4f;
[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;*/
[Range(0, 1f)]
[SerializeField] private float lookAheadSpeedMultiplier = 0.25f;
[SerializeField] private float minSpeed = 0.01f;
private float playerMovingTime;
private Vector3 lastPlayerPosition;
......@@ -57,6 +57,42 @@ public class CameraController : MonoBehaviour
{
return;
}
bool playerMoving = (player.transform.position - lastPlayerPosition).magnitude > 0.1f;
playerMovingTime += playerMoving ? Time.deltaTime : -Time.deltaTime;
playerMovingTime = Mathf.Clamp(playerMovingTime, 0f, lookaheadDelay * 2f);
ApplyPlayerMovement();
Vector3 currentOffset = transform.position - player.transform.position;
Vector3 targetOffset = offset;
float moveSpeedMultiplier = (lookaheadDelay - playerMovingTime) / lookaheadDelay;
if (playerMovingTime > lookaheadDelay) //apply lookahead
{
Vector2 playerVelocity2 = player.rigidbody.velocity.normalized;
Vector3 playerVelocity3 = new Vector3(playerVelocity2.x, playerVelocity2.y, 0f);
targetOffset += playerVelocity3 * lookaheadDistance;
if (playerMoving)
{
moveSpeedMultiplier *= -1 * lookAheadSpeedMultiplier;
}
}
moveSpeedMultiplier = Mathf.Max(moveSpeedMultiplier, 0f);
moveSpeedMultiplier *= panSpeed;
Vector3 targetMove = targetOffset - currentOffset;
Vector3 actualMove = targetMove * moveSpeedMultiplier;
Debug.Log(targetMove + ", " + actualMove);
if (actualMove.magnitude < minSpeed)
{
actualMove = actualMove.normalized * minSpeed;
}
actualMove *= Time.deltaTime;
if (actualMove.magnitude > targetMove.magnitude) //overshooting target in this frame
{
actualMove = targetMove;
}
transform.position += actualMove;
}
}
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