HandHeldCam.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using UnityEngine;
  3. namespace UnityStandardAssets.Cameras
  4. {
  5. public class HandHeldCam : LookatTarget
  6. {
  7. [SerializeField] private float m_SwaySpeed = .5f;
  8. [SerializeField] private float m_BaseSwayAmount = .5f;
  9. [SerializeField] private float m_TrackingSwayAmount = .5f;
  10. [Range(-1, 1)] [SerializeField] private float m_TrackingBias = 0;
  11. protected override void FollowTarget(float deltaTime)
  12. {
  13. base.FollowTarget(deltaTime);
  14. float bx = (Mathf.PerlinNoise(0, Time.time*m_SwaySpeed) - 0.5f);
  15. float by = (Mathf.PerlinNoise(0, (Time.time*m_SwaySpeed) + 100)) - 0.5f;
  16. bx *= m_BaseSwayAmount;
  17. by *= m_BaseSwayAmount;
  18. float tx = (Mathf.PerlinNoise(0, Time.time*m_SwaySpeed) - 0.5f) + m_TrackingBias;
  19. float ty = ((Mathf.PerlinNoise(0, (Time.time*m_SwaySpeed) + 100)) - 0.5f) + m_TrackingBias;
  20. tx *= -m_TrackingSwayAmount*m_FollowVelocity.x;
  21. ty *= m_TrackingSwayAmount*m_FollowVelocity.y;
  22. transform.Rotate(bx + tx, by + ty, 0);
  23. }
  24. }
  25. }