Enable Ragdoll on player death
This commit is contained in:
		
							parent
							
								
									7571a7fe7a
								
							
						
					
					
						commit
						925be65769
					
				| @ -3,6 +3,8 @@ | |||||||
| 
 | 
 | ||||||
| #include "PlayerCharacter.h" | #include "PlayerCharacter.h" | ||||||
| // You can remove these, this is just to get intellisense to work
 | // You can remove these, this is just to get intellisense to work
 | ||||||
|  | #include <Components/CapsuleComponent.h> | ||||||
|  | 
 | ||||||
| #include "InputTriggers.h" | #include "InputTriggers.h" | ||||||
| #include "EnhancedInputComponent.h" | #include "EnhancedInputComponent.h" | ||||||
| #include "EnhancedInputSubsystems.h" | #include "EnhancedInputSubsystems.h" | ||||||
| @ -232,7 +234,16 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits) | |||||||
| 	// Calculate starting position and direction
 | 	// Calculate starting position and direction
 | ||||||
| 	FVector TraceStart; | 	FVector TraceStart; | ||||||
| 	FRotator PlayerRot; | 	FRotator PlayerRot; | ||||||
| 	GetController<APlayerController>()->GetPlayerViewPoint(TraceStart, PlayerRot); | 
 | ||||||
|  | 	APlayerController* Con; | ||||||
|  | 	Con = GetController<APlayerController>(); | ||||||
|  | 
 | ||||||
|  | 	if (!Con) | ||||||
|  | 	{ | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	Con->GetPlayerViewPoint(TraceStart, PlayerRot); | ||||||
| 	TraceStart = GetRootComponent()->GetComponentLocation(); | 	TraceStart = GetRootComponent()->GetComponentLocation(); | ||||||
| 	FVector AimDir = PlayerRot.Vector(); | 	FVector AimDir = PlayerRot.Vector(); | ||||||
| 	TraceStart = TraceStart + AimDir * ((GetInstigator()->GetActorLocation() - TraceStart) | AimDir); | 	TraceStart = TraceStart + AimDir * ((GetInstigator()->GetActorLocation() - TraceStart) | AimDir); | ||||||
| @ -308,6 +319,30 @@ void APlayerCharacter::OnDeath() | |||||||
| { | { | ||||||
| 	Super::OnDeath(); | 	Super::OnDeath(); | ||||||
| 	UE_LOG(LogTemp, Error, TEXT("YOU ARE DEAD!")); | 	UE_LOG(LogTemp, Error, TEXT("YOU ARE DEAD!")); | ||||||
|  | 
 | ||||||
|  | 	this->DetachFromControllerPendingDestroy(); | ||||||
|  | 	this->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); | ||||||
|  | 	this->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); | ||||||
|  | 
 | ||||||
|  | 	this->GetMesh()->SetCollisionProfileName("Ragdoll"); | ||||||
|  | 	this->SetActorEnableCollision(true); | ||||||
|  | 
 | ||||||
|  | 	this->GetMesh()->SetAllBodiesSimulatePhysics(true); | ||||||
|  | 	this->GetMesh()->SetSimulatePhysics(true); | ||||||
|  | 	this->GetMesh()->WakeAllRigidBodies(); | ||||||
|  | 	this->GetMesh()->bBlendPhysics = true; | ||||||
|  | 
 | ||||||
|  | 	if (auto characterMovementComponent = this->GetCharacterMovement()) | ||||||
|  | 	{ | ||||||
|  | 		characterMovementComponent->StopMovementImmediately(); | ||||||
|  | 		characterMovementComponent->DisableMovement(); | ||||||
|  | 		characterMovementComponent->SetComponentTickEnabled(false); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	this->SetLifeSpan(10.0f); | ||||||
|  | 
 | ||||||
|  | 	IsFiring = false; | ||||||
|  | 	ClearAllTimers(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance) | void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance) | ||||||
| @ -330,7 +365,7 @@ void APlayerCharacter::OnFire() | |||||||
| 	{ | 	{ | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 	 | ||||||
| 	CurrentWeapon->SetCurrentWeaponStatus(Firing); | 	CurrentWeapon->SetCurrentWeaponStatus(Firing); | ||||||
| 
 | 
 | ||||||
| 	TArray<FHitResult> Hits = TArray<FHitResult>(); | 	TArray<FHitResult> Hits = TArray<FHitResult>(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user