Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CharacterCommandSwim.c
Go to the documentation of this file.
1 // *************************************************************************************
2 // ! Animation Graph Constants Table
3 // *************************************************************************************
5 {
6  //------------------------------------------------------------------------------------------------
7  // constructor
8  void SCR_CharacterCommandSwimST(CharacterAnimationComponent pAnimationComponent)
9  {
10  m_CmdStartSwimming = pAnimationComponent.BindCommand("CMD_Swim");
11  m_VarSpeed = pAnimationComponent.BindVariableFloat("MovementSpeed");
12  m_VarDirection = pAnimationComponent.BindVariableFloat("MovementDirection");
13  m_TagIsSwimming = pAnimationComponent.BindTag("TagSwimming");
14  }
15 
16  TAnimGraphCommand m_CmdStartSwimming;
17  TAnimGraphVariable m_VarSpeed;
18  TAnimGraphVariable m_VarDirection;
19  TAnimGraphTag m_TagIsSwimming;
20 }
21 
22 // *************************************************************************************
23 // ! Fully Working Swimming implemented by AnimPhysCommandScripted
24 // *************************************************************************************
26 {
27  //------------------------------------------------------------------------------------------------
28  // constructor
29  void SCR_CharacterCommandSwim(BaseAnimPhysComponent pAnimPhysComponent, SCR_CharacterCommandSwimST pTable, ChimeraCharacter pCharacter, CharacterControllerComponent pController)
30  {
31  m_pCharacter = pCharacter;
32  m_AnimationComponent = CharacterAnimationComponent.Cast(pAnimPhysComponent);
33  m_Input = pController.GetInputContext();
34  m_Table = pTable;
35  }
36 
37  //------------------------------------------------------------------------------------------------
39  {
40  PreAnim_CallCommand(m_Table.m_CmdStartSwimming, 1, 1);
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  void EndSwimming()
45  {
46  PreAnim_CallCommand(m_Table.m_CmdStartSwimming, -1, 0);
47  }
48 
49  //------------------------------------------------------------------------------------------------
52  {
53  //vector pp = m_pPlayer.GetPosition();
54  //vector wl = HumanCommandSwim.WaterLevelCheck(m_pPlayer, pp);
55 
56  //m_fWaterLevelDepth = wl[0]; // whats water depth at player's position
57  //m_fCharacterDepth = wl[1]; // whats character depth at player's position
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  override void OnActivate()
62  {
63  StartSwimming();
64  m_AnimationComponent.PhysicsEnableGravity(false);
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  override void OnDeactivate()
69  {
70  Print("SCR_CharacterCommandSwim::OnDeactivate");
71  m_AnimationComponent.PhysicsEnableGravity(true);
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  // called to set values to animation graph processing
76  override void PreAnimUpdate(float pDt)
77  {
78  if (m_bNeedFinish)
79  {
80  EndSwimming();
81  return;
82  }
83 
84  // Print("SCR_CharacterCommandSwim::PreAnimUpdate: " + pDt.ToString());
85 
86  vector localDir;
87  float speed;
88  float heading;
89 
90  // get int movement
91  m_Input.GetMovement(speed, localDir);
92  heading = m_Input.GetHeadingAngle();
93 
95  float animSpeed = 0;
96 
97  if (speed > 0)
98  {
99  if (localDir[2] > 0.3)
100  {
101  if (speed > 2.0)
102  {
103  animSpeed = 3.0;
104  }
105  else
106  {
107  animSpeed = 2.0;
108  }
109  }
110  }
111 
113  PreAnim_SetFloat(m_Table.m_VarSpeed, animSpeed); // sets motion variable speed
114 
116 /* if (animSpeed <= 0)
117  {
118  // idle
119  PreAnim_SetFilteredHeading(heading, m_pSettings.m_fAlignIdleTimeout, m_pSettings.m_fAlignIdleMaxChanged);
120  }
121  else if (animSpeed <= 2)
122  {
123  // normal speed
124  PreAnim_SetFilteredHeading(heading, m_pSettings.m_fAlignSlowTimeout, m_pSettings.m_fAlignSlowMaxChanged);
125  }
126  else
127  {
128  // sprint
129  PreAnim_SetFilteredHeading(heading, m_pSettings.m_fAlignFastTimeout, m_pSettings.m_fAlignFastMaxChanged);
130  }*/
131 
133  m_fTime += pDt;
134  }
135 
136  //------------------------------------------------------------------------------------------------
139  override void PrePhysUpdate(float pDt)
140  {
141  Print("SCR_CharacterCommandSwim::PrePhysUpdate: " + pDt.ToString());
142 
144  // Print("Char Depth: " + m_fCharacterDepth.ToString());
145 
147  float filtCharDepth = Math.SmoothCD(m_fCharacterDepth, m_fWaterLevelSwim, m_fWaterAlignV, 0.3, 1.0, pDt);
148  // Print("Filt Depth: " + filtCharDepth.ToString());
149 
151  float delta = m_fCharacterDepth - filtCharDepth;
152  // Print("Filt Delta: " + delta);
153 
155  vector trans = vector.Zero;
156 
158  PrePhys_GetTranslation(trans); // in case this returns false ... trans is still zero
159 
160  // waves
161  delta += Math.Sin(m_fTime * 3) * 0.003;
162 
164  trans[1] = trans[1] + delta;
165 
167  vector locDir;
168  float speed;
169  float swimSpeedX = 0, swimSpeedZ = 0;
170 
171  // get int movement
172  m_Input.GetMovement(speed, locDir);
173 
174  if (speed > 0)
175  {
176  if (locDir[2] < 0) // backwards ?
177  {
178  swimSpeedZ = locDir[2] * m_fMovementSpeed;
179  }
180 
181  swimSpeedX = locDir[0] * m_fMovementSpeed;
182  }
183 
184  // filter velocities
187 
188  // add velocity
189  trans[0] = trans[0] + m_fSpeedX * pDt;
190  trans[2] = trans[2] + m_fSpeedZ * pDt;
191 
193  PrePhys_SetTranslation(trans);
194  }
195 
196  //------------------------------------------------------------------------------------------------
198  override bool PostPhysUpdate(float pDt)
199  {
200  Print("SCR_CharacterCommandSwim::PostPhysUpdate: " + pDt.ToString());
201 
202  if (m_bNeedFinish)
203  {
204  return false;
205  }
206 
209  {
210  m_bNeedFinish = true; // let it run 1 frame more
211  }
212 
213  return true; // handled with SetFlagFinished();
214  }
215 
216  ChimeraCharacter m_pCharacter;
218  CharacterAnimationComponent m_AnimationComponent;
219 
221  float m_fTime;
223 
227 
228  float m_fSpeedX;
229  float m_fSpeedZ;
230  float m_fSpeedXV;
231  float m_fSpeedZV;
232 
234  float m_fMovementSpeed = 0.7;
237  float m_fWaterLevelSwim = 1.4;
238  float m_fWaterLevelIn = 1.5;
239  float m_fWaterLevelOut = 1.3;
240 }
m_bNeedFinish
bool m_bNeedFinish
Definition: SCR_CharacterCommandSwim.c:222
m_pCharacter
ChimeraCharacter m_pCharacter
Definition: SCR_CharacterCommandSwim.c:216
m_fWaterLevelSwim
float m_fWaterLevelSwim
when swimming - entity position depth (1.4 m)
Definition: SCR_CharacterCommandSwim.c:237
m_Input
CharacterInputContext m_Input
Definition: SCR_CharacterCommandSwim.c:217
CharacterInputContext
Definition: CharacterInputContext.c:12
m_fMovementSpeed
float m_fMovementSpeed
filter value
Definition: SCR_CharacterCommandSwim.c:234
m_fSpeedX
float m_fSpeedX
filter value
Definition: SCR_CharacterCommandSwim.c:228
m_fSpeedZV
float m_fSpeedZV
filter value
Definition: SCR_CharacterCommandSwim.c:231
m_AnimationComponent
CharacterAnimationComponent m_AnimationComponent
Definition: SCR_CharacterCommandSwim.c:218
SCR_CharacterCommandSwim
class SCR_CharacterCommandSwimST SCR_CharacterCommandSwim(BaseAnimPhysComponent pAnimPhysComponent, SCR_CharacterCommandSwimST pTable, ChimeraCharacter pCharacter, CharacterControllerComponent pController)
Definition: SCR_CharacterCommandSwim.c:29
StartSwimming
void StartSwimming()
Definition: SCR_CharacterCommandSwim.c:38
OnActivate
override void OnActivate()
Definition: SCR_CharacterCommandSwim.c:61
m_fWaterLevelDepth
float m_fWaterLevelDepth
Definition: SCR_CharacterCommandSwim.c:224
m_fMovementSpeedFltTime
float m_fMovementSpeedFltTime
Definition: SCR_CharacterCommandSwim.c:235
m_fCharacterDepth
float m_fCharacterDepth
water depth
Definition: SCR_CharacterCommandSwim.c:225
SCR_CharacterCommandSwimST
Definition: SCR_CharacterCommandSwim.c:4
ScriptedCommand
Definition: ScriptedCommand.c:12
m_fTime
float m_fTime
Definition: SCR_CharacterCommandSwim.c:221
m_fWaterAlignV
float m_fWaterAlignV
char's depth
Definition: SCR_CharacterCommandSwim.c:226
PreAnimUpdate
override void PreAnimUpdate(float pDt)
Definition: SCR_CharacterCommandSwim.c:76
UpdateWaterDepth
void UpdateWaterDepth()
empty, does nothing
Definition: SCR_CharacterCommandSwim.c:51
PostPhysUpdate
override bool PostPhysUpdate(float pDt)
called when all animation / pre phys update is handled
Definition: SCR_CharacterCommandSwim.c:198
m_fMovementSpeedFltMaxChange
float m_fMovementSpeedFltMaxChange
Definition: SCR_CharacterCommandSwim.c:236
m_fWaterLevelIn
float m_fWaterLevelIn
when entering water - what level cases swimming (1.5m)
Definition: SCR_CharacterCommandSwim.c:238
m_fWaterLevelOut
float m_fWaterLevelOut
Definition: SCR_CharacterCommandSwim.c:239
EndSwimming
void EndSwimming()
Definition: SCR_CharacterCommandSwim.c:44
PrePhysUpdate
override void PrePhysUpdate(float pDt)
Definition: SCR_CharacterCommandSwim.c:139
m_fSpeedXV
float m_fSpeedXV
x speed
Definition: SCR_CharacterCommandSwim.c:230
m_Table
SCR_CharacterCommandSwimST m_Table
Definition: SCR_CharacterCommandSwim.c:220
OnDeactivate
override void OnDeactivate()
Definition: SCR_CharacterCommandSwim.c:68
m_fSpeedZ
float m_fSpeedZ
x speed
Definition: SCR_CharacterCommandSwim.c:229