Post by jgiroux on Aug 19, 2016 3:57:25 GMT
Shake Camera Effect is always a welcome addition.
create a new c# script and call it "CameraShakeAddOn" (without the quotes).
open up that script and remove everything in there. copy and paste the below code. then save/compile/build.
using UnityEngine;
using System.Collections;
using Invector.CharacterController;
using Invector;
// simple script addon for InvectorCamera to allow screenshakes
// feel free to use as is or edited
public class CameraShakeAddOn : MonoBehaviour
{
private Vector3 MainCamera_OriginalPosition;
private Quaternion MainCamera_OriginalRotation;
private float MainCamera_ShakeStrength;
//public variables
public vThirdPersonController myController; // link thirdPersonController //
public float Intensity = 0.02f; // intensity of CameraShake
public float DecayTime = 0.001f; // how long it takes camera to return to normal
public bool ShakeCamera; // a easy public bool to trigger when to shake camera
public void Update()
{
if (myController != null) // if controller is not active ignore
{
if (myController.GetComponent<vThirdPersonMotor>().hud.damaged == true)
{
ShakeCamera = true;
}
}
if (ShakeCamera == true)
{
Shake();
ShakeCamera = false;
}
if (MainCamera_ShakeStrength > 0)
{
transform.position = MainCamera_OriginalPosition + Random.insideUnitSphere * MainCamera_ShakeStrength;
transform.rotation = new Quaternion
(
MainCamera_OriginalRotation.x + Random.Range(-MainCamera_ShakeStrength, MainCamera_ShakeStrength) * .2f,
MainCamera_OriginalRotation.y + Random.Range(-MainCamera_ShakeStrength, MainCamera_ShakeStrength) * .2f,
MainCamera_OriginalRotation.z + Random.Range(-MainCamera_ShakeStrength, MainCamera_ShakeStrength) * .2f,
MainCamera_OriginalRotation.w + Random.Range(-MainCamera_ShakeStrength, MainCamera_ShakeStrength) * .2f
);
MainCamera_ShakeStrength -= DecayTime;
}
}
private void Shake() // function to shake camera
{
MainCamera_OriginalPosition = transform.position;
MainCamera_OriginalRotation = transform.rotation;
MainCamera_ShakeStrength = Intensity;
}
}
Now add this script to your 3rdPersonCamera.
Steps.
1) Drag your Player Character into the "MyController" field in your Inspector
2) Adjust (if you like, however its set up with decent values) Intensity (how crazy the screen shakes)
3) Adjust (if you like, however its set up with decent values) DecayTime (how long it takes for camera to return to normal)
that's it. go try it out and have an enemy damage you, should trigger the screen shake.
of course, this script could be vastly improved upon, but its a start and works out of box, as it will check your Invectors Player for a Damage call and trigger the screen shake., but I made the ShakeScreen Boolean trigger a public variable, so you can call it from your own scripts to make further use of it.
also, this actually shakes screen on player damage, not on skills and attacks. but using the public bool as I mentioned you could easily access it a number of ways, just by setting MainCamera.GetComponent<CameraShakeAddOn>().ShakeCamera = true;