Advertisement
MrKeks

Perlin Noise Handheld Camera Movements

Sep 4th, 2020 (edited)
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class HandheldCamera : MonoBehaviour {
  4.  
  5.     public bool Active = true;
  6.     public float PositionFrequency = 0.4f;
  7.     public float RotationFrequency = 0.3f;
  8.     public Vector3 PositionStrength = new Vector3(0.2f, 0.2f, 0);
  9.     public Vector3 RotationStrength = new Vector3(0, 0, 0.2f);
  10.     private float seed;
  11.  
  12.     private void Awake() {
  13.         seed = Random.value;
  14.     }
  15.  
  16.     private void LateUpdate() {
  17.         if(!Active) return;
  18.  
  19.         transform.localPosition = new Vector3(
  20.             PositionStrength.x * (Mathf.PerlinNoise(seed, Time.time * PositionFrequency) - 0.5f),
  21.             PositionStrength.y * (Mathf.PerlinNoise(seed + 1, Time.time * PositionFrequency) - 0.5f),
  22.             PositionStrength.z * (Mathf.PerlinNoise(seed + 2, Time.time * PositionFrequency) - 0.5f)
  23.         );
  24.  
  25.         transform.localRotation = Quaternion.Euler(new Vector3(
  26.             RotationStrength.x * (Mathf.PerlinNoise(seed + 3, Time.time * RotationFrequency) - 0.5f),
  27.             RotationStrength.y * (Mathf.PerlinNoise(seed + 4, Time.time * RotationFrequency) - 0.5f),
  28.             RotationStrength.z * (Mathf.PerlinNoise(seed + 5, Time.time * RotationFrequency) - 0.5f)
  29.         ));        
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement