45 - Equipping Weapons
This commit is contained in:
parent
fe64e11281
commit
cd6b6e6241
|
@ -75,6 +75,7 @@ DefaultViewportMouseLockMode=LockOnCapture
|
||||||
FOVScale=0.011110
|
FOVScale=0.011110
|
||||||
DoubleClickTime=0.200000
|
DoubleClickTime=0.200000
|
||||||
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar)
|
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar)
|
||||||
|
+ActionMappings=(ActionName="Equip",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E)
|
||||||
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W)
|
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=W)
|
||||||
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S)
|
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=S)
|
||||||
+AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=D)
|
+AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=D)
|
||||||
|
|
Binary file not shown.
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "BlasterCharacter.h"
|
#include "BlasterCharacter.h"
|
||||||
|
|
||||||
|
#include "Blaster/Components/CombatComponent.h"
|
||||||
#include "Blaster/Weapon/Weapon.h"
|
#include "Blaster/Weapon/Weapon.h"
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Components/WidgetComponent.h"
|
#include "Components/WidgetComponent.h"
|
||||||
|
@ -29,6 +30,9 @@ ABlasterCharacter::ABlasterCharacter()
|
||||||
|
|
||||||
OverheadWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("OverheadWidget"));
|
OverheadWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("OverheadWidget"));
|
||||||
OverheadWidget->SetupAttachment(RootComponent);
|
OverheadWidget->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
|
Combat = CreateDefaultSubobject<UCombatComponent>(TEXT("CombatComponent"));
|
||||||
|
Combat->SetIsReplicated(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||||
|
@ -38,6 +42,16 @@ void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Ou
|
||||||
DOREPLIFETIME_CONDITION(ABlasterCharacter, OverlappingWeapon, COND_OwnerOnly);
|
DOREPLIFETIME_CONDITION(ABlasterCharacter, OverlappingWeapon, COND_OwnerOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterCharacter::PostInitializeComponents()
|
||||||
|
{
|
||||||
|
Super::PostInitializeComponents();
|
||||||
|
|
||||||
|
if (Combat)
|
||||||
|
{
|
||||||
|
Combat->Character = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::BeginPlay()
|
void ABlasterCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
@ -53,6 +67,8 @@ void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCo
|
||||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
|
|
||||||
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
|
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
|
||||||
|
PlayerInputComponent->BindAction("Equip", IE_Pressed, this, &ABlasterCharacter::EquipButtonPressed);
|
||||||
|
|
||||||
PlayerInputComponent->BindAxis("MoveForward", this, &ABlasterCharacter::MoveForward);
|
PlayerInputComponent->BindAxis("MoveForward", this, &ABlasterCharacter::MoveForward);
|
||||||
PlayerInputComponent->BindAxis("MoveRight", this, &ABlasterCharacter::MoveRight);
|
PlayerInputComponent->BindAxis("MoveRight", this, &ABlasterCharacter::MoveRight);
|
||||||
PlayerInputComponent->BindAxis("Turn", this, &ABlasterCharacter::Turn);
|
PlayerInputComponent->BindAxis("Turn", this, &ABlasterCharacter::Turn);
|
||||||
|
@ -91,6 +107,14 @@ void ABlasterCharacter::LookUp(float Value)
|
||||||
AddControllerPitchInput(Value);
|
AddControllerPitchInput(Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterCharacter::EquipButtonPressed()
|
||||||
|
{
|
||||||
|
if (Combat && HasAuthority())
|
||||||
|
{
|
||||||
|
Combat->EquipWeapon(OverlappingWeapon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::SetOverlappingWeapon(AWeapon* Weapon)
|
void ABlasterCharacter::SetOverlappingWeapon(AWeapon* Weapon)
|
||||||
{
|
{
|
||||||
if (OverlappingWeapon)
|
if (OverlappingWeapon)
|
||||||
|
|
|
@ -16,6 +16,8 @@ public:
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||||
|
virtual void PostInitializeComponents() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ protected:
|
||||||
void MoveRight(float Value);
|
void MoveRight(float Value);
|
||||||
void Turn(float Value);
|
void Turn(float Value);
|
||||||
void LookUp(float Value);
|
void LookUp(float Value);
|
||||||
|
void EquipButtonPressed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleAnywhere, Category="Camera")
|
UPROPERTY(VisibleAnywhere, Category="Camera")
|
||||||
|
@ -40,6 +43,9 @@ private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnRep_OverlappingWeapon(AWeapon* LastWeapon);
|
void OnRep_OverlappingWeapon(AWeapon* LastWeapon);
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
class UCombatComponent* Combat;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetOverlappingWeapon(AWeapon* Weapon);
|
void SetOverlappingWeapon(AWeapon* Weapon);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "CombatComponent.h"
|
||||||
|
|
||||||
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
|
#include "Blaster/Weapon/Weapon.h"
|
||||||
|
#include "Engine/SkeletalMeshSocket.h"
|
||||||
|
|
||||||
|
UCombatComponent::UCombatComponent()
|
||||||
|
{
|
||||||
|
PrimaryComponentTick.bCanEverTick = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UCombatComponent::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||||
|
{
|
||||||
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip)
|
||||||
|
{
|
||||||
|
if (Character == nullptr || WeaponToEquip == nullptr) return;
|
||||||
|
|
||||||
|
EquippedWeapon = WeaponToEquip;
|
||||||
|
EquippedWeapon->SetWeaponState(EWeaponState::EWS_Equipped);
|
||||||
|
const USkeletalMeshSocket* HandSocket = Character->GetMesh()->GetSocketByName(FName("RightHandSocket"));
|
||||||
|
if (HandSocket)
|
||||||
|
{
|
||||||
|
HandSocket->AttachActor(EquippedWeapon, Character->GetMesh());
|
||||||
|
}
|
||||||
|
EquippedWeapon->SetOwner(Character);
|
||||||
|
EquippedWeapon->ShowPickupWidget(false);
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Components/ActorComponent.h"
|
||||||
|
#include "CombatComponent.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||||
|
class BLASTER_API UCombatComponent : public UActorComponent
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UCombatComponent();
|
||||||
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
friend class ABlasterCharacter;
|
||||||
|
|
||||||
|
void EquipWeapon(class AWeapon* WeaponToEquip);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
class ABlasterCharacter* Character;
|
||||||
|
class AWeapon* EquippedWeapon;
|
||||||
|
};
|
|
@ -12,6 +12,7 @@ enum class EWeaponState : uint8
|
||||||
EWS_Initial UMETA(DisplayName = "Initial State"),
|
EWS_Initial UMETA(DisplayName = "Initial State"),
|
||||||
EWS_Equipped UMETA(DisplayName = "Equipped"),
|
EWS_Equipped UMETA(DisplayName = "Equipped"),
|
||||||
EWS_Dropped UMETA(DisplayName = "Dropped"),
|
EWS_Dropped UMETA(DisplayName = "Dropped"),
|
||||||
|
|
||||||
EWS_MAX UMETA(DisplayName = "DefaultMAX")
|
EWS_MAX UMETA(DisplayName = "DefaultMAX")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,4 +60,5 @@ private:
|
||||||
class UWidgetComponent* PickupWidget;
|
class UWidgetComponent* PickupWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
FORCEINLINE void SetWeaponState(EWeaponState State) { WeaponState = State; };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue