1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
| using Boo.Lang;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
[AddComponentMenu("Character/Character Motor"), RequireComponent(typeof(CharacterController))]
[Serializable]
public class CharacterMotor : MonoBehaviour
{
[Serializable]
internal sealed class _SubtractNewPlatformVelocity_3 : GenericGenerator<object>
{
[Serializable]
internal sealed class _ : GenericGeneratorEnumerator<object>, IEnumerator
{
internal Transform _platform_4;
internal CharacterMotor _self__5;
public _(CharacterMotor self_)
{
this._self__5 = self_;
}
public bool MoveNext()
{
switch (this._state)
{
case 0:
IL_1F:
if (!this._self__5.movingPlatform.enabled || (this._self__5.movingPlatform.movementTransfer != MovementTransferOnJump.InitTransfer && this._self__5.movingPlatform.movementTransfer != MovementTransferOnJump.PermaTransfer))
{
goto IL_124;
}
if (this._self__5.movingPlatform.newPlatform)
{
this._platform_4 = this._self__5.movingPlatform.activePlatform;
int arg_12D_0 = this.Yield(2, new WaitForFixedUpdate()) ? 1 : 0;
return arg_12D_0 != 0;
}
goto IL_EF;
case 1:
{
IL_12C:
int arg_12D_0 = 0;
return arg_12D_0 != 0;
}
case 2:
{
int arg_12D_0 = this.Yield(3, new WaitForFixedUpdate()) ? 1 : 0;
return arg_12D_0 != 0;
}
case 3:
if (this._self__5.grounded && this._platform_4 == this._self__5.movingPlatform.activePlatform)
{
int arg_12D_0 = this.Yield(4, 1) ? 1 : 0;
return arg_12D_0 != 0;
}
goto IL_EF;
case 4:
goto IL_EF;
}
goto IL_1F;
IL_EF:
this._self__5.movement.velocity = this._self__5.movement.velocity - this._self__5.movingPlatform.platformVelocity;
IL_124:
this.YieldDefault(1);
goto IL_12C;
}
}
internal CharacterMotor _self__6;
public _SubtractNewPlatformVelocity_3(CharacterMotor self_)
{
this._self__6 = self_;
}
public IEnumerator<object> GetEnumerator()
{
return new CharacterMotor._SubtractNewPlatformVelocity_3._(this._self__6);
}
}
public bool canControl;
public bool useFixedUpdate;
[NonSerialized]
public Vector3 inputMoveDirection;
[NonSerialized]
public bool inputJump;
public CharacterMotorMovement movement;
public CharacterMotorJumping jumping;
public CharacterMotorMovingPlatform movingPlatform;
public CharacterMotorSliding sliding;
[NonSerialized]
public bool grounded;
[NonSerialized]
public Vector3 groundNormal;
private Vector3 lastGroundNormal;
private Transform tr;
private CharacterController controller;
public CharacterMotor()
{
this.canControl = true;
this.useFixedUpdate = true;
this.inputMoveDirection = Vector3.zero;
this.movement = new CharacterMotorMovement();
this.jumping = new CharacterMotorJumping();
this.movingPlatform = new CharacterMotorMovingPlatform();
this.sliding = new CharacterMotorSliding();
this.grounded = true;
this.groundNormal = Vector3.zero;
this.lastGroundNormal = Vector3.zero;
}
public void Awake()
{
this.controller = (CharacterController)this.GetComponent(typeof(CharacterController));
this.tr = this.transform;
}
private void UpdateFunction()
{
Vector3 vector = this.movement.velocity;
vector = this.ApplyInputVelocityChange(vector);
vector = this.ApplyGravityAndJumping(vector);
Vector3 vector2 = Vector3.zero;
if (this.MoveWithPlatform())
{
Vector3 a = this.movingPlatform.activePlatform.TransformPoint(this.movingPlatform.activeLocalPoint);
vector2 = a - this.movingPlatform.activeGlobalPoint;
if (vector2 != Vector3.zero)
{
this.controller.Move(vector2);
}
Quaternion lhs = this.movingPlatform.activePlatform.rotation * this.movingPlatform.activeLocalRotation;
float y = (lhs * Quaternion.Inverse(this.movingPlatform.activeGlobalRotation)).eulerAngles.y;
if (y != (float)0)
{
this.tr.Rotate((float)0, y, (float)0);
}
}
Vector3 position = this.tr.position;
Vector3 vector3 = vector * Time.deltaTime;
float d = Mathf.Max(this.controller.stepOffset, new Vector3(vector3.x, (float)0, vector3.z).magnitude);
if (this.grounded)
{
vector3 -= d * Vector3.up;
}
this.movingPlatform.hitPlatform = null;
this.groundNormal = Vector3.zero;
this.movement.collisionFlags = this.controller.Move(vector3);
this.movement.lastHitPoint = this.movement.hitPoint;
this.lastGroundNormal = this.groundNormal;
if (this.movingPlatform.enabled && this.movingPlatform.activePlatform != this.movingPlatform.hitPlatform && this.movingPlatform.hitPlatform != null)
{
this.movingPlatform.activePlatform = this.movingPlatform.hitPlatform;
this.movingPlatform.lastMatrix = this.movingPlatform.hitPlatform.localToWorldMatrix;
this.movingPlatform.newPlatform = true;
}
Vector3 vector4 = new Vector3(vector.x, (float)0, vector.z);
this.movement.velocity = (this.tr.position - position) / Time.deltaTime;
Vector3 lhs2 = new Vector3(this.movement.velocity.x, (float)0, this.movement.velocity.z);
if (vector4 == Vector3.zero)
{
this.movement.velocity = new Vector3((float)0, this.movement.velocity.y, (float)0);
}
else
{
float value = Vector3.Dot(lhs2, vector4) / vector4.sqrMagnitude;
this.movement.velocity = vector4 * Mathf.Clamp01(value) + this.movement.velocity.y * Vector3.up;
}
if (this.movement.velocity.y < vector.y - 0.001f)
{
if (this.movement.velocity.y < (float)0)
{
this.movement.velocity.y = vector.y;
}
else
{
this.jumping.holdingJumpButton = false;
}
}
if (this.grounded && !this.IsGroundedTest())
{
this.grounded = false;
if (this.movingPlatform.enabled && (this.movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer || this.movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer))
{
this.movement.frameVelocity = this.movingPlatform.platformVelocity;
this.movement.velocity = this.movement.velocity + this.movingPlatform.platformVelocity;
}
this.SendMessage("OnFall", SendMessageOptions.DontRequireReceiver);
this.tr.position = this.tr.position + d * Vector3.up;
}
else if (!this.grounded && this.IsGroundedTest())
{
this.grounded = true;
this.jumping.jumping = false;
this.StartCoroutine(this.SubtractNewPlatformVelocity());
this.SendMessage("OnLand", SendMessageOptions.DontRequireReceiver);
}
if (this.MoveWithPlatform())
{
this.movingPlatform.activeGlobalPoint = this.tr.position + Vector3.up * (this.controller.center.y - this.controller.height * 0.5f + this.controller.radius);
this.movingPlatform.activeLocalPoint = this.movingPlatform.activePlatform.InverseTransformPoint(this.movingPlatform.activeGlobalPoint);
this.movingPlatform.activeGlobalRotation = this.tr.rotation;
this.movingPlatform.activeLocalRotation = Quaternion.Inverse(this.movingPlatform.activePlatform.rotation) * this.movingPlatform.activeGlobalRotation;
}
}
public void FixedUpdate()
{
if (this.movingPlatform.enabled)
{
if (this.movingPlatform.activePlatform != null)
{
if (!this.movingPlatform.newPlatform)
{
Vector3 platformVelocity = this.movingPlatform.platformVelocity;
this.movingPlatform.platformVelocity = (this.movingPlatform.activePlatform.localToWorldMatrix.MultiplyPoint3x4(this.movingPlatform.activeLocalPoint) - this.movingPlatform.lastMatrix.MultiplyPoint3x4(this.movingPlatform.activeLocalPoint)) / Time.deltaTime;
}
this.movingPlatform.lastMatrix = this.movingPlatform.activePlatform.localToWorldMatrix;
this.movingPlatform.newPlatform = false;
}
else
{
this.movingPlatform.platformVelocity = Vector3.zero;
}
}
if (this.useFixedUpdate)
{
this.UpdateFunction();
}
}
public void Update()
{
if (!this.useFixedUpdate)
{
this.UpdateFunction();
}
}
private Vector3 ApplyInputVelocityChange(Vector3 velocity)
{
if (!this.canControl)
{
this.inputMoveDirection = Vector3.zero;
}
Vector3 vector = default(Vector3);
if (this.grounded && this.TooSteep())
{
vector = new Vector3(this.groundNormal.x, (float)0, this.groundNormal.z).normalized;
Vector3 vector2 = Vector3.Project(this.inputMoveDirection, vector);
vector = vector + vector2 * this.sliding.speedControl + (this.inputMoveDirection - vector2) * this.sliding.sidewaysControl;
vector *= this.sliding.slidingSpeed;
}
else
{
vector = this.GetDesiredHorizontalVelocity();
}
if (this.movingPlatform.enabled && this.movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
{
vector += this.movement.frameVelocity;
vector.y = (float)0;
}
if (this.grounded)
{
vector = this.AdjustGroundVelocityToNormal(vector, this.groundNormal);
}
else
{
velocity.y = (float)0;
}
float num = this.GetMaxAcceleration(this.grounded) * Time.deltaTime;
Vector3 b = vector - velocity;
if (b.sqrMagnitude > num * num)
{
b = b.normalized * num;
}
if (this.grounded || this.canControl)
{
velocity += b;
}
if (this.grounded)
{
velocity.y = Mathf.Min(velocity.y, (float)0);
}
return velocity;
}
private Vector3 ApplyGravityAndJumping(Vector3 velocity)
{
if (!this.inputJump || !this.canControl)
{
this.jumping.holdingJumpButton = false;
this.jumping.lastButtonDownTime = (float)(-100);
}
if (this.inputJump && this.jumping.lastButtonDownTime < (float)0 && this.canControl)
{
this.jumping.lastButtonDownTime = Time.time;
}
if (this.grounded)
{
velocity.y = Mathf.Min((float)0, velocity.y) - this.movement.gravity * Time.deltaTime;
}
else
{
velocity.y = this.movement.velocity.y - this.movement.gravity * Time.deltaTime;
if (this.jumping.jumping && this.jumping.holdingJumpButton && Time.time < this.jumping.lastStartTime + this.jumping.extraHeight / this.CalculateJumpVerticalSpeed(this.jumping.baseHeight))
{
velocity += this.jumping.jumpDir * this.movement.gravity * Time.deltaTime;
}
velocity.y = Mathf.Max(velocity.y, -this.movement.maxFallSpeed);
}
if (this.grounded)
{
if (this.jumping.enabled && this.canControl && Time.time - this.jumping.lastButtonDownTime < 0.2f)
{
this.grounded = false;
this.jumping.jumping = true;
this.jumping.lastStartTime = Time.time;
this.jumping.lastButtonDownTime = (float)(-100);
this.jumping.holdingJumpButton = true;
if (this.TooSteep())
{
this.jumping.jumpDir = Vector3.Slerp(Vector3.up, this.groundNormal, this.jumping.steepPerpAmount);
}
else
{
this.jumping.jumpDir = Vector3.Slerp(Vector3.up, this.groundNormal, this.jumping.perpAmount);
}
velocity.y = (float)0;
velocity += this.jumping.jumpDir * this.CalculateJumpVerticalSpeed(this.jumping.baseHeight);
if (this.movingPlatform.enabled && (this.movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer || this.movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer))
{
this.movement.frameVelocity = this.movingPlatform.platformVelocity;
velocity += this.movingPlatform.platformVelocity;
}
this.SendMessage("OnJump", SendMessageOptions.DontRequireReceiver);
}
else
{
this.jumping.holdingJumpButton = false;
}
}
return velocity;
}
public void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.normal.y > (float)0 && hit.normal.y > this.groundNormal.y && hit.moveDirection.y < (float)0)
{
if ((hit.point - this.movement.lastHitPoint).sqrMagnitude > 0.001f || this.lastGroundNormal == Vector3.zero)
{
this.groundNormal = hit.normal;
}
else
{
this.groundNormal = this.lastGroundNormal;
}
this.movingPlatform.hitPlatform = hit.collider.transform;
this.movement.hitPoint = hit.point;
this.movement.frameVelocity = Vector3.zero;
}
}
private IEnumerator SubtractNewPlatformVelocity()
{
return new CharacterMotor._SubtractNewPlatformVelocity_3(this).GetEnumerator();
}
private bool MoveWithPlatform()
{
bool arg_2D_0;
if (arg_2D_0 = this.movingPlatform.enabled)
{
arg_2D_0 = (this.grounded ?? (this.movingPlatform.movementTransfer == MovementTransferOnJump.PermaLocked));
}
bool arg_45_0;
if (arg_45_0 = arg_2D_0)
{
arg_45_0 = (this.movingPlatform.activePlatform != null);
}
return arg_45_0;
}
private Vector3 GetDesiredHorizontalVelocity()
{
Vector3 vector = this.tr.InverseTransformDirection(this.inputMoveDirection);
float num = this.MaxSpeedInDirection(vector);
if (this.grounded)
{
float time = Mathf.Asin(this.movement.velocity.normalized.y) * 57.29578f;
num *= this.movement.slopeSpeedMultiplier.Evaluate(time);
}
return this.tr.TransformDirection(vector * num);
}
private Vector3 AdjustGroundVelocityToNormal(Vector3 hVelocity, Vector3 groundNormal)
{
Vector3 lhs = Vector3.Cross(Vector3.up, hVelocity);
return Vector3.Cross(lhs, groundNormal).normalized * hVelocity.magnitude;
}
private bool IsGroundedTest()
{
return this.groundNormal.y > 0.01f;
}
public float GetMaxAcceleration(bool grounded)
{
return (!grounded) ? this.movement.maxAirAcceleration : this.movement.maxGroundAcceleration;
}
public float CalculateJumpVerticalSpeed(float targetJumpHeight)
{
return Mathf.Sqrt((float)2 * targetJumpHeight * this.movement.gravity);
}
public bool IsJumping()
{
return this.jumping.jumping;
}
public bool IsSliding()
{
bool arg_18_0;
if (arg_18_0 = this.grounded)
{
arg_18_0 = this.sliding.enabled;
}
bool arg_25_0;
if (arg_25_0 = arg_18_0)
{
arg_25_0 = this.TooSteep();
}
return arg_25_0;
}
public bool IsTouchingCeiling()
{
return (this.movement.collisionFlags & CollisionFlags.Above) != CollisionFlags.None;
}
public bool IsGrounded()
{
return this.grounded;
}
public bool TooSteep()
{
return this.groundNormal.y <= Mathf.Cos(this.controller.slopeLimit * 0.0174532924f);
}
public Vector3 GetDirection()
{
return this.inputMoveDirection;
}
public void SetControllable(bool controllable)
{
this.canControl = controllable;
}
public float MaxSpeedInDirection(Vector3 desiredMovementDirection)
{
float arg_AC_0;
if (desiredMovementDirection == Vector3.zero)
{
arg_AC_0 = (float)0;
}
else
{
float num = ((desiredMovementDirection.z <= (float)0) ? this.movement.maxBackwardsSpeed : this.movement.maxForwardSpeed) / this.movement.maxSidewaysSpeed;
Vector3 normalized = new Vector3(desiredMovementDirection.x, (float)0, desiredMovementDirection.z / num).normalized;
float num2 = new Vector3(normalized.x, (float)0, normalized.z * num).magnitude * this.movement.maxSidewaysSpeed;
arg_AC_0 = num2;
}
return arg_AC_0;
}
public void SetVelocity(Vector3 velocity)
{
this.grounded = false;
this.movement.velocity = velocity;
this.movement.frameVelocity = Vector3.zero;
this.SendMessage("OnExternalVelocity");
}
public void Main()
{
}
} |