camerashake.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. class CameraShake
  2. {
  3. const float MIN_PLAYER_DISTANCE = 40;
  4. float m_Radius;
  5. float m_RadiusDecaySpeed;
  6. float m_RandomAngle;
  7. float m_Time;
  8. float m_InitLR;
  9. float m_InitUD;
  10. bool m_ToDelete;
  11. float m_Smoothness;
  12. float m_StregthFactor;
  13. DayZPlayerImplement m_Player;
  14. void ~CameraShake()
  15. {
  16. if(m_Player)
  17. m_Player.GetAimingModel().SetCamShakeValues(0, 0);
  18. }
  19. void CameraShake( float strength_factor, float radius, float smoothness, float radius_decay_speed )
  20. {
  21. /*
  22. Print("-----------ON CREATE------------");
  23. Print(camera_offset);
  24. Print("-----------ON CREATE END------------");
  25. */
  26. //m_Player = DayZPlayerImplement.Cast(player);
  27. m_Player = DayZPlayerImplement.Cast(GetGame().GetPlayer());
  28. m_StregthFactor = strength_factor;
  29. //m_InitLR = lr_angle;
  30. //m_InitUD = ud_angle;
  31. m_Radius = radius;
  32. m_RadiusDecaySpeed = radius_decay_speed;
  33. m_Smoothness = smoothness;
  34. }
  35. void Update(float delta_time, out float x_axis, out float y_axis)
  36. {
  37. if(m_ToDelete)
  38. delete this;
  39. m_Radius -= delta_time * m_RadiusDecaySpeed; //diminish radius each frame
  40. if( m_RandomAngle >= 0 )
  41. {
  42. m_RandomAngle = -m_Radius + (Math.RandomFloat( -m_Radius / m_Smoothness, m_Radius / m_Smoothness));
  43. }
  44. else
  45. {
  46. m_RandomAngle = m_Radius + (Math.RandomFloat( -m_Radius / m_Smoothness, m_Radius / m_Smoothness));
  47. }
  48. x_axis = m_RandomAngle * m_StregthFactor;
  49. y_axis = m_RandomAngle * m_StregthFactor;
  50. //Print(x_axis);
  51. //Print(y_axis);
  52. if( m_Radius < 0.01 )
  53. {
  54. m_ToDelete = true;
  55. }
  56. }
  57. }