MCPcopy Create free account
hub / github.com/Vaei/PredictedMovement / Prone

Method Prone

Source/PredictedMovement/Private/Prone/ProneMovement.cpp:174–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174void UProneMovement::Prone(bool bClientSimulation)
175{
176 if (!HasValidData())
177 {
178 return;
179 }
180
181 if (!bClientSimulation && !CanProneInCurrentState())
182 {
183 return;
184 }
185
186 // See if collision is already at desired size.
187 if (CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight() == PronedHalfHeight &&
188 CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleRadius() == PronedRadius)
189 {
190 if (!bClientSimulation)
191 {
192 ProneCharacterOwner->SetIsProned(true);
193 }
194 ProneCharacterOwner->OnStartProne( 0.f, 0.f );
195 SetProneLock(true);
196 return;
197 }
198
199 if (bClientSimulation && CharacterOwner->GetLocalRole() == ROLE_SimulatedProxy)
200 {
201 // restore collision size before prone
202 const ACharacter* DefaultCharacter = CharacterOwner->GetClass()->GetDefaultObject<ACharacter>();
203 CharacterOwner->GetCapsuleComponent()->SetCapsuleSize(DefaultCharacter->GetCapsuleComponent()->GetUnscaledCapsuleRadius(), DefaultCharacter->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight());
204 bShrinkProxyCapsule = true;
205 }
206
207 // Change collision size to prone dimensions
208 const float ComponentScale = CharacterOwner->GetCapsuleComponent()->GetShapeScale();
209 const float OldUnscaledHalfHeight = CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight();
210 const float OldUnscaledRadius = CharacterOwner->GetCapsuleComponent()->GetUnscaledCapsuleRadius();
211
212 // Height is not allowed to be smaller than radius.
213 const float ClampedPronedHalfHeight = FMath::Max3(0.f, PronedRadius, PronedHalfHeight);
214 CharacterOwner->GetCapsuleComponent()->SetCapsuleSize(PronedRadius, ClampedPronedHalfHeight);
215 float HalfHeightAdjust = (OldUnscaledHalfHeight - ClampedPronedHalfHeight);
216 float ScaledHalfHeightAdjust = HalfHeightAdjust * ComponentScale;
217
218 if( !bClientSimulation )
219 {
220 // Proned to a larger height? (this is rare)
221 if (ClampedPronedHalfHeight > OldUnscaledHalfHeight)
222 {
223 FCollisionQueryParams CapsuleParams(SCENE_QUERY_STAT(ProneTrace), false, CharacterOwner);
224 FCollisionResponseParams ResponseParam;
225 InitCollisionParams(CapsuleParams, ResponseParam);
226 const bool bEncroached = GetWorld()->OverlapBlockingTestByChannel(UpdatedComponent->GetComponentLocation() - FVector(0.f,0.f,ScaledHalfHeightAdjust), FQuat::Identity,
227 UpdatedComponent->GetCollisionObjectType(), GetPawnCapsuleCollisionShape(SHRINK_None), CapsuleParams, ResponseParam);
228
229 // If encroached, cancel
230 if( bEncroached )
231 {

Callers

nothing calls this directly

Calls 2

SetIsPronedMethod · 0.80
OnStartProneMethod · 0.80

Tested by

no test coverage detected