GunSettings.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using UnityEngine;
  3. namespace HQFPSWeapons
  4. {
  5. public class GunSettings
  6. {
  7. [Serializable]
  8. public class Shooting
  9. {
  10. [BHeader("General Settings")]
  11. [Tooltip("The layers that will be affected when you fire.")]
  12. public LayerMask Mask;
  13. [Tooltip("If something is farther than this distance threeshold, it will not be affected by the shot.")]
  14. public float MaxDistance = 150f;
  15. [Range(1, 20)]
  16. [Tooltip("The amount of rays that will be sent in the world " +
  17. "(basically the amount of projectiles / bullets that will be fired at a time).")]
  18. public int RayCount = 1;
  19. public HitscanImpact RayImpact;
  20. [Range(0f, 2f)]
  21. public float AimThreeshold = 0.35f;
  22. [BHeader("Ray Spread")]
  23. [Tooltip("How the bullet spread will transform (in continuous use) on the duration of the magazine, the max x value(1) will be used if the whole magazine has been used")]
  24. public AnimationCurve SpreadOverTime = new AnimationCurve(
  25. new Keyframe(0f, .8f),
  26. new Keyframe(1f, 1f));
  27. [Range(0f, 3f)]
  28. public float AimSpreadFactor = 0.8f;
  29. [Range(0f, 3f)]
  30. public float CrouchSpreadFactor = 0.95f;
  31. [Range(0f, 3f)]
  32. public float WalkSpreadFactor = 0.95f;
  33. [Range(0f, 3f)]
  34. public float RunSpreadFactor = 0.95f;
  35. [Range(0f, 3f)]
  36. public float JumpSpreadFactor = 1.5f;
  37. }
  38. [Serializable]
  39. public class HitscanImpact
  40. {
  41. [Range(0f, 1000f)]
  42. [SerializeField]
  43. [Tooltip("The damage at close range.")]
  44. private float m_MaxDamage = 15f;
  45. [Range(0f, 1000f)]
  46. [SerializeField]
  47. [Tooltip("The impact impulse that will be transfered to the rigidbodies at contact.")]
  48. private float m_MaxImpulse = 15f;
  49. [SerializeField]
  50. [Tooltip("How damage and impulse lowers over distance.")]
  51. private AnimationCurve m_DistanceCurve = new AnimationCurve(
  52. new Keyframe(0f, 1f),
  53. new Keyframe(0.8f, 0.5f),
  54. new Keyframe(1f, 0f));
  55. /// <summary>
  56. ///
  57. /// </summary>
  58. /// <param name="distance"></param>
  59. /// <param name="maxDistance"></param>
  60. public float GetDamageAtDistance(float distance, float maxDistance)
  61. {
  62. return ApplyCurveToValue(m_MaxDamage, distance, maxDistance);
  63. }
  64. /// <summary>
  65. ///
  66. /// </summary>
  67. /// <returns>The impulse at distance.</returns>
  68. /// <param name="distance">Distance.</param>
  69. /// <param name="maxDistance">Max distance.</param>
  70. public float GetImpulseAtDistance(float distance, float maxDistance)
  71. {
  72. return ApplyCurveToValue(m_MaxImpulse, distance, maxDistance);
  73. }
  74. private float ApplyCurveToValue(float value, float distance, float maxDistance)
  75. {
  76. float maxDistanceAbsolute = Mathf.Abs(maxDistance);
  77. float distanceClamped = Mathf.Clamp(distance, 0f, maxDistanceAbsolute);
  78. return value * m_DistanceCurve.Evaluate(distanceClamped / maxDistanceAbsolute);
  79. }
  80. }
  81. }
  82. }