Add camera effects

This commit is contained in:
Jens Pitkänen 2019-08-04 19:35:08 +03:00
parent 36fc251da5
commit 18e3cff7b5
4 changed files with 5292 additions and 329 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Saltosion.OneWeapon {
[RequireComponent(typeof(Camera))]
public class CameraFX : MonoBehaviour {
public Transform Player;
public Transform ShakeHandle;
public bool DebugShake = false;
public bool DebugSlowDown = false;
private Camera Camera;
private Vector3 Offset;
private float ScreenShakeTime = 0.0f;
private float ScreenShakeIntensity = 0.0f;
private float TimeStopCooldown = 0.0f;
private void Start() {
Camera = GetComponent<Camera>();
Offset = transform.position;
}
private void Update() {
if (DebugShake) {
DebugShake = false;
ScreenShake(10f);
}
if (DebugSlowDown) {
DebugSlowDown = false;
StopFor(10f);
}
if (TimeStopCooldown > 0) {
TimeStopCooldown -= Time.deltaTime / Time.timeScale;
if (TimeStopCooldown <= 0) {
Time.timeScale = 1.0f;
}
}
Vector2 TargetPosition = (Player.position + Camera.ScreenToWorldPoint(Input.mousePosition)) / 2.0f;
transform.position = Vector3.Lerp(transform.position, TargetPosition, 5f * Time.deltaTime / Time.timeScale) + Offset;
if (ScreenShakeTime > 0) {
ScreenShakeTime -= Time.deltaTime;
ShakeHandle.localPosition = new Vector2(Random.value, Random.value) *
Mathf.Pow(ScreenShakeTime, 2f) * ScreenShakeIntensity * Random.value;
}
}
public void StopFor(float seconds) {
Time.timeScale = 0.05f;
TimeStopCooldown = seconds;
}
public void ScreenShake(float intensity) {
ScreenShakeIntensity = intensity;
ScreenShakeTime = 0.2f;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fac21b42a74f79846a19753e7644f26c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -19,6 +19,8 @@ namespace Saltosion.OneWeapon {
public Transform HandRight;
public Transform HandMiddle;
public CameraFX CameraFX;
private Gun Gun;
private Vector2 GunLocation = new Vector2(0, -0.6f);
@ -93,6 +95,8 @@ namespace Saltosion.OneWeapon {
bool Shoot = Input.GetButtonDown("Shoot");
if (Shoot && Gun != null) {
Gun.Shoot(LookDirection, Rotation);
CameraFX.StopFor(0.03f);
CameraFX.ScreenShake(4f);
}
}