Camera shake effect when player stands on the ground for a long time,camera shake effect when unity player touches the ground
I want to make camera flicker effect when unity player touches the ground my flickering code is like this but how can I trigger it? I want the camera to make a shaking effect when my character stands on the ground for a long time.`using UnityEngine; using System.Collections; public class cameraShake : MonoBehaviour { private Vector3 originPosition; private Quaternion originRotation; public float shake_decay; public float shake_intensity;
void OnGUI()
{
if (GUI.Button(new Rect(20, 40, 80, 20), "Shake"))
{
Shake();
}
}
void Update()
{
if (shake_intensity > 0)
{
transform.position = originPosition + Random.insideUnitSphere * shake_intensity;
transform.rotation = new Quaternion(
originRotation.x + Random.Range(-shake_intensity, shake_intensity) * .2f,
originRotation.y + Random.Range(-shake_intensity, shake_intensity) * .2f,
originRotation.z + Random.Range(-shake_intensity, shake_intensity) * .2f,
originRotation.w + Random.Range(-shake_intensity, shake_intensity) * .2f);
shake_intensity -= shake_decay;
}
}
void Shake()
{
originPosition = transform.position;
originRotation = transform.rotation;
shake_intensity = .3f;
shake_decay = 0.002f;
}
}` ,I want to make camera flicker effect when unity player touches the ground my flickering code is like this but how can I trigger it? I want the camera to make a shaking effect when my character stands on the ground for a long time. using UnityEngine; using System.Collections; public class cameraShake : MonoBehaviour { private Vector3 originPosition; private Quaternion originRotation; public float shake_decay; public float shake_intensity;
void OnGUI()
{
if (GUI.Button(new Rect(20, 40, 80, 20), "Shake"))
{
Shake();
}
}
void Update()
{
if (shake_intensity > 0)
{
transform.position = originPosition + Random.insideUnitSphere * shake_intensity;
transform.rotation = new Quaternion(
originRotation.x + Random.Range(-shake_intensity, shake_intensity) * .2f,
originRotation.y + Random.Range(-shake_intensity, shake_intensity) * .2f,
originRotation.z + Random.Range(-shake_intensity, shake_intensity) * .2f,
originRotation.w + Random.Range(-shake_intensity, shake_intensity) * .2f);
shake_intensity -= shake_decay;
}
}
void Shake()
{
originPosition = transform.position;
originRotation = transform.rotation;
shake_intensity = .3f;
shake_decay = 0.002f;
}
}
Your answer
Follow this Question
Related Questions
How to get the camera to follow a prefab? 2 Answers
Camera Reset Script 1 Answer
How to see a prefab from inside it? 1 Answer
How can I change the viewport rect of two active cameras at runtime? - Splitscreen Multiplayer 1 Answer
how to resize my orthographic Camera to fit a dynamically generated grid of cubes(Mine Sweeper) 0 Answers