Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_CharacterCommandSwim.c
Go to the documentation of this file.
1
// *************************************************************************************
2
// ! Animation Graph Constants Table
3
// *************************************************************************************
4
class
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
// *************************************************************************************
25
class
SCR_CharacterCommandSwim
:
ScriptedCommand
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
//------------------------------------------------------------------------------------------------
38
void
StartSwimming
()
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
//------------------------------------------------------------------------------------------------
51
void
UpdateWaterDepth
()
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
143
UpdateWaterDepth
();
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
185
m_fSpeedX
=
Math
.SmoothCD(
m_fSpeedX
, swimSpeedX,
m_fSpeedXV
,
m_fMovementSpeedFltTime
,
m_fMovementSpeedFltMaxChange
, pDt);
186
m_fSpeedZ
=
Math
.SmoothCD(
m_fSpeedZ
, swimSpeedZ,
m_fSpeedZV
,
m_fMovementSpeedFltTime
,
m_fMovementSpeedFltMaxChange
, pDt);
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
208
if
(
m_fWaterLevelDepth
<
m_fWaterLevelOut
)
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
;
217
CharacterInputContext
m_Input
;
218
CharacterAnimationComponent
m_AnimationComponent;
219
220
SCR_CharacterCommandSwimST
m_Table
;
221
float
m_fTime
;
222
bool
m_bNeedFinish
;
223
224
float
m_fWaterLevelDepth
;
225
float
m_fCharacterDepth
;
226
float
m_fWaterAlignV
;
227
228
float
m_fSpeedX
;
229
float
m_fSpeedZ
;
230
float
m_fSpeedXV
;
231
float
m_fSpeedZV
;
232
234
float
m_fMovementSpeed
= 0.7;
235
float
m_fMovementSpeedFltTime
= 0.3;
236
float
m_fMovementSpeedFltMaxChange
= 1;
237
float
m_fWaterLevelSwim
= 1.4;
238
float
m_fWaterLevelIn
= 1.5;
239
float
m_fWaterLevelOut
= 1.3;
240
}
TAnimGraphVariable
int TAnimGraphVariable
Definition
ECommandIDs.c:2
TAnimGraphTag
int TAnimGraphTag
Definition
ECommandIDs.c:3
TAnimGraphCommand
int TAnimGraphCommand
Definition
ECommandIDs.c:1
m_pCharacter
ChimeraCharacter m_pCharacter
Definition
SCR_CharacterCommandLoiter.c:190
m_bNeedFinish
bool m_bNeedFinish
Definition
SCR_CharacterCommandSwim.c:222
m_fSpeedZV
float m_fSpeedZV
filter value
Definition
SCR_CharacterCommandSwim.c:231
UpdateWaterDepth
void UpdateWaterDepth()
empty, does nothing
Definition
SCR_CharacterCommandSwim.c:51
m_Table
SCR_CharacterCommandSwimST m_Table
Definition
SCR_CharacterCommandSwim.c:220
m_Input
CharacterInputContext m_Input
Definition
SCR_CharacterCommandSwim.c:217
m_fCharacterDepth
float m_fCharacterDepth
water depth
Definition
SCR_CharacterCommandSwim.c:225
m_fWaterLevelIn
float m_fWaterLevelIn
when entering water - what level cases swimming (1.5m)
Definition
SCR_CharacterCommandSwim.c:238
SCR_CharacterCommandSwim
class SCR_CharacterCommandSwimST SCR_CharacterCommandSwim(BaseAnimPhysComponent pAnimPhysComponent, SCR_CharacterCommandSwimST pTable, ChimeraCharacter pCharacter, CharacterControllerComponent pController)
Definition
SCR_CharacterCommandSwim.c:29
m_fWaterLevelDepth
float m_fWaterLevelDepth
Definition
SCR_CharacterCommandSwim.c:224
m_fMovementSpeedFltTime
float m_fMovementSpeedFltTime
Definition
SCR_CharacterCommandSwim.c:235
m_fMovementSpeed
float m_fMovementSpeed
filter value
Definition
SCR_CharacterCommandSwim.c:234
EndSwimming
void EndSwimming()
Definition
SCR_CharacterCommandSwim.c:44
m_fSpeedXV
float m_fSpeedXV
x speed
Definition
SCR_CharacterCommandSwim.c:230
m_fWaterAlignV
float m_fWaterAlignV
char's depth
Definition
SCR_CharacterCommandSwim.c:226
m_fWaterLevelOut
float m_fWaterLevelOut
Definition
SCR_CharacterCommandSwim.c:239
m_fWaterLevelSwim
float m_fWaterLevelSwim
when swimming - entity position depth (1.4 m)
Definition
SCR_CharacterCommandSwim.c:237
m_fSpeedX
float m_fSpeedX
filter value
Definition
SCR_CharacterCommandSwim.c:228
StartSwimming
void StartSwimming()
Definition
SCR_CharacterCommandSwim.c:38
m_fTime
float m_fTime
Definition
SCR_CharacterCommandSwim.c:221
m_fSpeedZ
float m_fSpeedZ
x speed
Definition
SCR_CharacterCommandSwim.c:229
m_fMovementSpeedFltMaxChange
float m_fMovementSpeedFltMaxChange
Definition
SCR_CharacterCommandSwim.c:236
AnimPhysCommandScripted::PreAnimUpdate
void PreAnimUpdate(float pDt)
AnimPhysCommandScripted::PrePhys_GetTranslation
proto native bool PrePhys_GetTranslation(out vector pOutTransl)
AnimPhysCommandScripted::PrePhysUpdate
void PrePhysUpdate(float pDt)
AnimPhysCommandScripted::PreAnim_SetFloat
proto native void PreAnim_SetFloat(int pVar, float pFlt)
AnimPhysCommandScripted::PostPhysUpdate
bool PostPhysUpdate(float pDt)
AnimPhysCommandScripted::OnDeactivate
void OnDeactivate()
called when command ends
AnimPhysCommandScripted::PrePhys_SetTranslation
proto native void PrePhys_SetTranslation(vector pInTransl)
AnimPhysCommandScripted::PreAnim_CallCommand
proto native void PreAnim_CallCommand(int pCommand, int pParamInt, float pParamFloat)
AnimPhysCommandScripted::OnActivate
void OnActivate()
BaseAnimPhysComponent
Definition
BaseAnimPhysComponent.c:13
CharacterAnimationComponent
Definition
CharacterAnimationComponent.c:13
CharacterInputContext
Definition
CharacterInputContext.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
Math
Definition
Math.c:13
SCR_CharacterCommandSwimST
Definition
SCR_CharacterCommandSwim.c:5
ScriptedCommand
Definition
ScriptedCommand.c:13
vector
Definition
vector.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
scripts
Game
Character
Examples
SCR_CharacterCommandSwim.c
Generated by
1.17.0