|
Post by marcrem on Feb 7, 2018 16:34:59 GMT
Here's a very simple script I made to add camera shake when desired. What this script gives you is a simple slider with the shake amount. Not that it uses the rotation offset of the Invector Camera. So if you are using an offset, it probably won't work for you, or you'll have to tweak the code a little. Simply create a new C# script and name it CameraShake. Attach this script to your Invector Camera, and play with the shakeAmount slider. Example: imgur.com/a/QQvvTimgur.com/a/QQvvTusing System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraShake : MonoBehaviour {
[Range(0, 1)] public float shakeAmount = 0;
public float maxDistance = 1;
vThirdPersonCamera vCam;
void Awake () { vCam = GetComponent<vThirdPersonCamera>(); } void Update () { Shake(); }
void Shake() { if(shakeAmount > 0) { float x = Random.Range(-maxDistance * shakeAmount, maxDistance * shakeAmount); float y = Random.Range(-maxDistance * shakeAmount, maxDistance * shakeAmount); float z = Random.Range(-maxDistance * shakeAmount, maxDistance * shakeAmount);
vCam.currentState.rotationOffSet.x = x; vCam.currentState.rotationOffSet.y = y; vCam.currentState.rotationOffSet.z = z; } } }
|
|
|
Post by tharindu on Feb 12, 2018 1:09:04 GMT
I would add some perlin noise along with your offset. Looks more natural that way :D
|
|