Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CharacterCamera3rdPersonProne.c
Go to the documentation of this file.
1 // *************************************************************************************
2 // ! CharacterCamera3rdPersonProne - 3rd person camera in prone stance
3 // *************************************************************************************
4 class CharacterCamera3rdPersonProne extends CharacterCamera3rdPersonBase
5 {
6  static private const float FREELOOK_FADE_SPEED = 4.0;
7  static private const float SLOPE_FACTOR = 1.0 / 90.0;
8 
9  private float m_fFreelookBlend;
10 
11  //-----------------------------------------------------------------------------
12  void CharacterCamera3rdPersonProne(CameraHandlerComponent pCameraHandler)
13  {
14  m_fDistance = 1.4;
15  m_CameraOffsetMS = "0.0 0.3 0.0";
16  m_CameraOffsetLS = "0.0 0.2 0.0";
17  m_fShoulderWidth = 0.4;
18  }
19 
20  //-----------------------------------------------------------------------------
21  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
22  {
23  pOutResult.m_fFOV = m_fFOV;
24  float nextMSOffset = 0.2;
25  bool sprinting = m_ControllerComponent.IsSprinting();
26  if( sprinting )
27  pOutResult.m_fFOV = m_fFOV + 2 * m_fBobScale;
28 
29  HandleFreelook(pDt, pOutResult);
30 
31  super.OnUpdate(pDt, pOutResult);
32 
33  // Apply shake
34  if (m_CharacterCameraHandler)
35  m_CharacterCameraHandler.AddShakeToToTransform(pOutResult.m_CameraTM, pOutResult.m_fFOV);
36  }
37 
38  void HandleFreelook(float pDt, inout ScriptedCameraItemResult pOutResult)
39  {
40  vector charaRot = m_OwnerCharacter.GetLocalYawPitchRoll();
41 
42  float tSlope = Math.Clamp(charaRot[1] * SLOPE_FACTOR, -1.0, 1.0); // [-1, 1]
43  float tSlopeUp = Math.Clamp(tSlope, 0.0, 1.0); // [0, 1]
44  float tSlopeDn = Math.Clamp(tSlope, -1.0, 0.0) * -1.0; // [0, 1]
45 
46  if (m_ControllerComponent.IsFreeLookEnabled())
47  {
48  m_fFreelookBlend = Math.Clamp(m_fFreelookBlend + FREELOOK_FADE_SPEED * pDt, 0.0, 1.0); // Fade-in the effect
49 
50  // Override angle limits based on terrain slope
51  float downLimit = Math.Lerp(-60.0, 0.0, tSlopeDn);
52  float upLimit = Math.Lerp(89.9, 40.0, tSlope);
53  float leftLimit = Math.Lerp(-160.0, -40.0, tSlope);
54  float rightLimit = Math.Lerp(160.0, 80.0, tSlope);
55  m_CharacterHeadAimingComponent.SetLimitAnglesOverride(downLimit, upLimit, leftLimit, rightLimit);
56  }
57  else
58  {
59  m_fFreelookBlend = Math.Clamp(m_fFreelookBlend - FREELOOK_FADE_SPEED * pDt, 0.0, 1.0); // Fade-out the effect
60 
61  m_CharacterHeadAimingComponent.ResetLimitAnglesOverride();
62  }
63 
64  vector lookAngles = m_CharacterHeadAimingComponent.GetLookAngles();
65 
66  // Limit yaw on slopes.
67  float yawMax = Math.Lerp(160.0, 40.0, Math.Max(0.0, tSlope));
68  lookAngles[0] = Math.Clamp(lookAngles[0], -yawMax, yawMax); // Clamp backtrace direction's Yaw
69  float tYaw = Math.InverseLerp(0.0, 160.0, Math.AbsFloat(lookAngles[0]));
70 
71  float lookPitch = lookAngles[1] + charaRot[1]; // Save current pitch to be used later
72  lookAngles[1] = Math.Lerp(charaRot[1], -charaRot[1], tYaw); // Calc. backtrace direction's Pitch
73 
74  pOutResult.m_vBacktraceDir = lookAngles.AnglesToVector(); // Custom backtrace direction
75 
76  // Blend into using custom backtrace usiong as the camera looks up.
77  const float pitchMin = Math.Lerp(-10.0, -charaRot[1], tYaw);
78  const float pitchMax = pitchMin + 20.0;
79  float alpha = Math.InverseLerp(pitchMin, pitchMax, Math.Clamp(lookPitch, pitchMin, pitchMax));
80  pOutResult.m_fUseBacktraceDir = m_fFreelookBlend * alpha; // Use custom backtrace direction
81 
82  // Additionally, tweak the PitchLimitReduction curve multiplier
83  float pitchReductionMultiplier = 1.0;
84  pitchReductionMultiplier = Math.Lerp(1.0, 0.7, tSlopeUp);
85  m_CharacterHeadAimingComponent.SetPitchLimitReductionMultiplier(Math.Lerp(1.0, pitchReductionMultiplier, m_fFreelookBlend));
86  }
87 };
m_fDistance
float m_fDistance
Definition: SCR_AIGroupTargetCluster.c:38
OnUpdate
override void OnUpdate(BaseWorld world, float timeslice)
Definition: game.c:910
CharacterCamera3rdPersonBase
Definition: CharacterCamera3rdPersonCrouch.c:4
m_OwnerCharacter
private SCR_ChimeraCharacter m_OwnerCharacter
Definition: CharacterCameraHandlerComponent.c:984
m_ControllerComponent
private SCR_CharacterControllerComponent m_ControllerComponent
Definition: CharacterCameraHandlerComponent.c:985