Create separate Throw Weapon and Throw Explosive input actions

This commit is contained in:
baz 2023-09-13 14:55:56 +01:00
parent eea9ee49e6
commit 5a8c542581
6 changed files with 53 additions and 13 deletions

BIN
Content/Input/Actions/IA_ThrowExplosive.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Input/Actions/IA_ThrowWeapon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Input/InputMappingContext.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -13,7 +13,7 @@
#include "GameFramework/CharacterMovementComponent.h"
#include "InputMappingContext.h"
#include "EnemyCharacter.h"
#include "Throwable.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1
@ -171,9 +171,15 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
&APlayerCharacter::EndAimDownSightsCallback);
}
if (ThrowAction)
if (ThrowWeaponAction)
{
Input->BindAction(ThrowAction, ETriggerEvent::Started, this, &APlayerCharacter::ThrowThrowable);
Input->BindAction(ThrowWeaponAction, ETriggerEvent::Started, this, &APlayerCharacter::ThrowWeaponCallback);
}
if (ThrowExplosiveAction)
{
Input->BindAction(ThrowExplosiveAction, ETriggerEvent::Started, this,
&APlayerCharacter::ThrowExplosiveCallback);
}
}
}
@ -568,7 +574,25 @@ float APlayerCharacter::GetWeaponSpread()
return CurrentWeapon->GetWeaponProperties()->WeaponSpread;
}
void APlayerCharacter::ThrowThrowable()
void APlayerCharacter::ThrowWeaponCallback()
{
auto throwable = ThrowThrowable();
// TODO: Set the collision size to the size of the static mesh in the throwable
// throwable->GetSphereComponent()->SetSphereRadius();
}
void APlayerCharacter::ThrowExplosiveCallback()
{
auto throwable = ThrowThrowable();
// TODO: Set the collision size to the size of the static mesh in the throwable
// throwable->GetSphereComponent()->SetSphereRadius();
}
AThrowable* APlayerCharacter::ThrowThrowable()
{
FVector Location;
FVector BoxExtent;
@ -576,8 +600,10 @@ void APlayerCharacter::ThrowThrowable()
FVector SpawnLocation = FVector(Location.Z, Location.Y + (BoxExtent.Y / 2), Location.Z + (BoxExtent.Z / 2));
AThrowable* Throwable = GetWorld()->SpawnActor<AThrowable>(SpawnLocation, FRotator::ZeroRotator);
if (AThrowable* Throwable = GetWorld()->SpawnActor<AThrowable>(SpawnLocation, FRotator::ZeroRotator))
{
return Throwable;
}
// TODO: Set the collision size to the size of the static mesh in the throwable
//throwable->GetSphereComponent()->SetSphereRadius();
return nullptr;
}

View File

@ -14,6 +14,7 @@
#include "Blueprint/UserWidget.h"
#include "Perception/AIPerceptionStimuliSourceComponent.h"
#include "InteractableComponent.h"
#include "Throwable.h"
#include "PlayerCharacter.generated.h"
class UInputAction;
@ -49,8 +50,11 @@ public:
UInputAction* SprintAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* ThrowAction;
UInputAction* ThrowWeaponAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* ThrowExplosiveAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSoftObjectPtr<UInputMappingContext> InputMappingContext;
@ -178,7 +182,11 @@ public:
UFUNCTION(BlueprintCallable)
float GetWeaponSpread();
void ThrowThrowable();
void ThrowWeaponCallback();
void ThrowExplosiveCallback();
AThrowable* ThrowThrowable();
protected:
virtual void CalculateHits(TArray<FHitResult>* hits) override;