@@ -41,6 +41,8 @@ APBPlayerCharacter::APBPlayerCharacter(const FObjectInitializer& ObjectInitializ
41
41
42
42
// get pointer to movement component
43
43
MovementPtr = Cast<UPBPlayerMovement>(ACharacter::GetMovementComponent ());
44
+
45
+ CapDamageMomentumZ = 476 .25f ;
44
46
}
45
47
46
48
void APBPlayerCharacter::BeginPlay ()
@@ -51,16 +53,75 @@ void APBPlayerCharacter::BeginPlay()
51
53
MaxJumpTime = -4 .0f * GetCharacterMovement ()->JumpZVelocity / (3 .0f * GetCharacterMovement ()->GetGravityZ ());
52
54
}
53
55
56
+ void APBPlayerCharacter::Tick (float DeltaTime)
57
+ {
58
+ Super::Tick (DeltaTime);
59
+
60
+
61
+ if (bDeferJumpStop)
62
+ {
63
+ bDeferJumpStop = false ;
64
+ Super::StopJumping ();
65
+ }
66
+ }
67
+
68
+ void APBCharacter::ApplyDamageMomentum (float DamageTaken, FDamageEvent const & DamageEvent, APawn* PawnInstigator, AActor* DamageCauser)
69
+ {
70
+ UDamageType const * const DmgTypeCDO = DamageEvent.DamageTypeClass ->GetDefaultObject <UDamageType>();
71
+ if (GetCharacterMovement ())
72
+ {
73
+ FVector ImpulseDir;
74
+
75
+ if (IsValid (DamageCauser))
76
+ {
77
+ ImpulseDir = (GetActorLocation () - (DamageCauser->GetActorLocation () + FVector (0 .0f , 0 .0f , HU_TO_UU (-10 .0f )))).GetSafeNormal ();
78
+ }
79
+ else
80
+ {
81
+ ImpulseDir = DamageEvent.GetImpulse (DamageTaken, this , PawnInstigator).GetSafeNormal ();
82
+ }
83
+
84
+ const float SizeFactor = (FMath::Square (HU_TO_UU (32 .0f )) * HU_TO_UU (72 .0f )) / (FMath::Square (GetCapsuleComponent ()->GetScaledCapsuleRadius () * 2 .0f ) * GetCapsuleComponent ()->GetScaledCapsuleHalfHeight () * 2 .0f );
85
+
86
+ float Magnitude = HU_TO_UU (DamageTaken) * SizeFactor * 5 .0f ;
87
+ Magnitude = FMath::Min (Magnitude, HU_TO_UU (1000 .0f ));
88
+
89
+ FVector Impulse = ImpulseDir * Magnitude;
90
+ bool const bMassIndependentImpulse = !DmgTypeCDO->bScaleMomentumByMass ;
91
+ float MassScale = 1 .f ;
92
+ if (!bMassIndependentImpulse && GetCharacterMovement ()->Mass > SMALL_NUMBER)
93
+ {
94
+ MassScale = 1 .f / GetCharacterMovement ()->Mass ;
95
+ }
96
+ if (CapDamageMomentumZ > 0 .f )
97
+ {
98
+ Impulse.Z = FMath::Min (Impulse.Z * MassScale, CapDamageMomentumZ) / MassScale;
99
+ }
100
+
101
+ GetCharacterMovement ()->AddImpulse (Impulse, bMassIndependentImpulse);
102
+ }
103
+ }
104
+
54
105
void APBPlayerCharacter::ClearJumpInput (float DeltaTime)
55
106
{
56
- // Don't clear jump input right away if we're auto hopping or noclipping (holding to go up)
57
- if (CVarAutoBHop-> GetInt () != 0 || bAutoBunnyhop || GetCharacterMovement ()->bCheatFlying )
107
+ // Don't clear jump input right away if we're auto hopping or noclipping (holding to go up), or if we are deferring a jump stop
108
+ if (CVarAutoBHop. GetValueOnGameThread () != 0 || bAutoBunnyhop || GetCharacterMovement ()->bCheatFlying || bDeferJumpStop )
58
109
{
59
110
return ;
60
111
}
61
112
Super::ClearJumpInput (DeltaTime);
62
113
}
63
114
115
+ void APBPlayerCharacter::Jump ()
116
+ {
117
+ if (GetCharacterMovement ()->IsFalling ())
118
+ {
119
+ bDeferJumpStop = true ;
120
+ }
121
+
122
+ Super::Jump ();
123
+ }
124
+
64
125
void APBPlayerCharacter::OnMovementModeChanged (EMovementMode PrevMovementMode, uint8 PrevCustomMode)
65
126
{
66
127
if (!bPressedJump)
@@ -90,31 +151,28 @@ void APBPlayerCharacter::OnMovementModeChanged(EMovementMode PrevMovementMode, u
90
151
91
152
void APBPlayerCharacter::StopJumping ()
92
153
{
93
- Super::StopJumping ();
94
- if (GetCharacterMovement ()->bCheatFlying )
154
+ if (!bDeferJumpStop)
95
155
{
96
- Cast<UPBPlayerMovement>( GetMovementComponent ())-> NoClipVerticalMoveMode = 0 ;
156
+ Super::StopJumping () ;
97
157
}
98
158
}
99
159
100
160
void APBPlayerCharacter::OnJumped_Implementation ()
101
161
{
102
- LastJumpTime = GetWorld ()->GetTimeSeconds ();
103
- if (GetCharacterMovement ()->bCheatFlying )
162
+ if (MovementPtr->IsOnLadder ())
104
163
{
105
- MovementPtr-> NoClipVerticalMoveMode = 1 ;
164
+ return ;
106
165
}
107
- else if (GetWorld ()->GetTimeSeconds () >= LastJumpBoostTime + MaxJumpTime)
166
+
167
+ if (GetWorld ()->GetTimeSeconds () >= LastJumpBoostTime + MaxJumpTime)
108
168
{
109
169
LastJumpBoostTime = GetWorld ()->GetTimeSeconds ();
110
170
// Boost forward speed on jump
111
171
FVector Facing = GetActorForwardVector ();
112
- // Give it its backward/forward direction
113
- float ForwardSpeed;
114
172
FVector Input = MovementPtr->GetLastInputVector ().GetClampedToMaxSize2D (1 .0f ) * MovementPtr->GetMaxAcceleration ();
115
- ForwardSpeed = Input | Facing;
173
+ float ForwardSpeed = Input | Facing;
116
174
// Adjust how much the boost is
117
- float SpeedBoostPerc = ( bIsSprinting || bIsCrouched) ? 0 .1f : 0 .5f ;
175
+ float SpeedBoostPerc = bIsSprinting || bIsCrouched ? 0 .1f : 0 .5f ;
118
176
// How much we are boosting by
119
177
float SpeedAddition = FMath::Abs (ForwardSpeed * SpeedBoostPerc);
120
178
// We can only boost up to this much
@@ -139,7 +197,7 @@ void APBPlayerCharacter::OnJumped_Implementation()
139
197
// Boost our velocity
140
198
FVector JumpBoostedVel = GetMovementComponent ()->Velocity + Facing * SpeedAddition;
141
199
float JumpBoostedSizeSq = JumpBoostedVel.SizeSquared2D ();
142
- if (CVarBunnyhop-> GetInt () != 0 )
200
+ if (CVarBunnyhop. GetValueOnGameThread () != 0 )
143
201
{
144
202
FVector JumpBoostedUnclampVel = GetMovementComponent ()->Velocity + Facing * SpeedAdditionNoClamp;
145
203
float JumpBoostedUnclampSizeSq = JumpBoostedUnclampVel.SizeSquared2D ();
@@ -163,6 +221,8 @@ void APBPlayerCharacter::ToggleNoClip()
163
221
164
222
bool APBPlayerCharacter::CanJumpInternal_Implementation () const
165
223
{
224
+ // UE-COPY: ACharacter::CanJumpInternal_Implementation()
225
+
166
226
bool bCanJump = GetCharacterMovement () && GetCharacterMovement ()->IsJumpAllowed ();
167
227
168
228
if (bCanJump)
@@ -263,21 +323,19 @@ void APBPlayerCharacter::ApplyDamageMomentum(float DamageTaken, FDamageEvent con
263
323
}
264
324
}
265
325
266
- void APBPlayerCharacter::RecalculateBaseEyeHeight () {}
267
-
268
- bool APBPlayerCharacter::CanCrouch () const
326
+ void APBPlayerCharacter::RecalculateBaseEyeHeight ()
269
327
{
270
- return !GetCharacterMovement ()->bCheatFlying && Super::CanCrouch ();
328
+ const ACharacter* DefaultCharacter = GetClass ()->GetDefaultObject <ACharacter>();
329
+ const float OldUnscaledHalfHeight = DefaultCharacter->GetCapsuleComponent ()->GetUnscaledCapsuleHalfHeight ();
330
+ const float CrouchedHalfHeight = GetCharacterMovement ()->GetCrouchedHalfHeight ();
331
+ const float FullCrouchDiff = OldUnscaledHalfHeight - CrouchedHalfHeight;
332
+ const UCapsuleComponent* CharacterCapsule = GetCapsuleComponent ();
333
+ const float CurrentUnscaledHalfHeight = CharacterCapsule->GetUnscaledCapsuleHalfHeight ();
334
+ const float CurrentAlpha = 1 .0f - (CurrentUnscaledHalfHeight - CrouchedHalfHeight) / FullCrouchDiff;
335
+ BaseEyeHeight = FMath::Lerp (DefaultCharacter->BaseEyeHeight , CrouchedEyeHeight, UPBUtilityLibrary::SimpleSpline (CurrentAlpha));
271
336
}
272
337
273
- #if ENGINE_MAJOR_VERSION == 4
274
- void APBPlayerCharacter::RecalculateCrouchedEyeHeight ()
338
+ bool APBPlayerCharacter::CanCrouch () const
275
339
{
276
- if (GetCharacterMovement () != nullptr )
277
- {
278
- constexpr float EyeHeightRatio = 0 .8f ; // how high the character's eyes are, relative to the crouched height
279
-
280
- CrouchedEyeHeight = GetCharacterMovement ()->GetCrouchedHalfHeight () * EyeHeightRatio;
281
- }
340
+ return !GetCharacterMovement ()->bCheatFlying && Super::CanCrouch () && !(MovementPtr->IsOnLadder () || MovementPtr->IsInForcedMove ());
282
341
}
283
- #endif
0 commit comments