Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ShakeyCamera : MonoBehaviour {
- public float recoverStrength = 1;
- public AnimationCurve shakeCurve = new AnimationCurve(new Keyframe[]{ new Keyframe(0,0), new Keyframe(1,1)});
- public Transform shakePivot;
- Vector3 startPosition;
- Vector3 offset;
- float velocity;
- void Awake(){
- startPosition = shakePivot.localPosition;
- }
- void FixedUpdate(){
- velocity -= velocity * Time.deltaTime * recoverStrength;
- if(velocity > 0)
- offset = Random.insideUnitSphere * shakeCurve.Evaluate(velocity) * velocity;
- shakePivot.localPosition = startPosition + offset;
- }
- public void Shake(float force){
- velocity += force;
- }
- [ContextMenu("Shake")]
- void ShakeTest(){
- Shake(Random.value * 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment