Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CharacterCommandSwim.c
Go to the documentation of this file.
1// *************************************************************************************
2// ! Animation Graph Constants Table
3// *************************************************************************************
4class SCR_CharacterCommandSwimST
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 }
43 //------------------------------------------------------------------------------------------------
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 {
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 {
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
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
218 CharacterAnimationComponent m_AnimationComponent;
219
221 float m_fTime;
223
227
228 float m_fSpeedX;
229 float m_fSpeedZ;
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}
int TAnimGraphVariable
Definition ECommandIDs.c:2
int TAnimGraphTag
Definition ECommandIDs.c:3
int TAnimGraphCommand
Definition ECommandIDs.c:1
ChimeraCharacter m_pCharacter
bool m_bNeedFinish
float m_fSpeedZV
filter value
void UpdateWaterDepth()
empty, does nothing
SCR_CharacterCommandSwimST m_Table
CharacterInputContext m_Input
float m_fCharacterDepth
water depth
float m_fWaterLevelIn
when entering water - what level cases swimming (1.5m)
class SCR_CharacterCommandSwimST SCR_CharacterCommandSwim(BaseAnimPhysComponent pAnimPhysComponent, SCR_CharacterCommandSwimST pTable, ChimeraCharacter pCharacter, CharacterControllerComponent pController)
float m_fWaterLevelDepth
float m_fMovementSpeedFltTime
float m_fMovementSpeed
filter value
void EndSwimming()
float m_fSpeedXV
x speed
float m_fWaterAlignV
char's depth
float m_fWaterLevelOut
float m_fWaterLevelSwim
when swimming - entity position depth (1.4 m)
float m_fSpeedX
filter value
void StartSwimming()
float m_fSpeedZ
x speed
float m_fMovementSpeedFltMaxChange
void PreAnimUpdate(float pDt)
proto native bool PrePhys_GetTranslation(out vector pOutTransl)
void PrePhysUpdate(float pDt)
proto native void PreAnim_SetFloat(int pVar, float pFlt)
bool PostPhysUpdate(float pDt)
void OnDeactivate()
called when command ends
proto native void PrePhys_SetTranslation(vector pInTransl)
proto native void PreAnim_CallCommand(int pCommand, int pParamInt, float pParamFloat)
Definition Math.c:13
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.