feat: add simple shooting component
Added interface for damage. Added shooting component with simple shooting system. Fix missing action bindings in player controller. Added cylinder mesh to ExoEnemy and place him on TestMap.
This commit is contained in:
parent
40e5a37d91
commit
9e7fab3544
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,60 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Characters/Components/ShootingComponent.h"
|
||||||
|
|
||||||
|
// Sets default values for this component's properties
|
||||||
|
UShootingComponent::UShootingComponent()
|
||||||
|
{
|
||||||
|
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||||||
|
// off to improve performance if you don't need them.
|
||||||
|
PrimaryComponentTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Called when the game starts
|
||||||
|
void UShootingComponent::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
// ...
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UShootingComponent::Shoot()
|
||||||
|
{
|
||||||
|
AActor* Owner = GetOwner();
|
||||||
|
|
||||||
|
FVector LineStart = Owner->GetActorLocation();
|
||||||
|
FVector ForwardVector = Owner->GetActorForwardVector();
|
||||||
|
FVector LineEnd = LineStart + (ForwardVector * MaxRange);
|
||||||
|
|
||||||
|
FHitResult HitResult;
|
||||||
|
FCollisionQueryParams QueryParams;
|
||||||
|
QueryParams.AddIgnoredActor(Owner);
|
||||||
|
|
||||||
|
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
|
||||||
|
|
||||||
|
if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements<UDamageable>())
|
||||||
|
{
|
||||||
|
IDamageable::Execute_TakeDamage(HitResult.GetActor(), DamageValue);
|
||||||
|
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("Shoot"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bShowDebugLine)
|
||||||
|
DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 1.0f, 0, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||||||
|
{
|
||||||
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -29,6 +29,7 @@ void AExoPlayerController::BeginPlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
|
||||||
|
ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerTick(float DeltaTime)
|
void AExoPlayerController::PlayerTick(float DeltaTime)
|
||||||
|
|
@ -47,6 +48,14 @@ void AExoPlayerController::SetupInputComponent()
|
||||||
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact);
|
||||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump);
|
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump);
|
||||||
EnhancedInputComponent->BindAction(DodgeAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDodge);
|
EnhancedInputComponent->BindAction(DodgeAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerDodge);
|
||||||
|
//EnhancedInputComponent->BindAction(, ETriggerEvent::Started, this, &AExoPlayerController::ResetDodge);
|
||||||
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerCrouch);
|
||||||
|
EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerSprint);
|
||||||
|
EnhancedInputComponent->BindAction(ShootAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerShoot);
|
||||||
|
EnhancedInputComponent->BindAction(AimAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerAim);
|
||||||
|
EnhancedInputComponent->BindAction(MeleAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerMeleAttack);
|
||||||
|
EnhancedInputComponent->BindAction(ChangeWeaponAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerChangeWeapon);
|
||||||
|
EnhancedInputComponent->BindAction(ReloadAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerReload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::Move(const FInputActionValue& InputActionValue)
|
void AExoPlayerController::Move(const FInputActionValue& InputActionValue)
|
||||||
|
|
@ -74,7 +83,7 @@ void AExoPlayerController::Look(const FInputActionValue& InputActionValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AExoPlayerController::Interact(const FInputActionValue& InputActionValue)
|
void AExoPlayerController::Interact()
|
||||||
{
|
{
|
||||||
if (InteractionComponent->InteractedActor)
|
if (InteractionComponent->InteractedActor)
|
||||||
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
IInteractable::Execute_Interact(InteractionComponent->InteractedActor);
|
||||||
|
|
@ -123,7 +132,7 @@ void AExoPlayerController::PlayerSprint()
|
||||||
|
|
||||||
void AExoPlayerController::PlayerShoot()
|
void AExoPlayerController::PlayerShoot()
|
||||||
{
|
{
|
||||||
|
ShootingComponent->Shoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AExoPlayerController::PlayerAim()
|
void AExoPlayerController::PlayerAim()
|
||||||
|
|
|
||||||
42
Source/Exo/Public/Characters/Components/ShootingComponent.h
Normal file
42
Source/Exo/Public/Characters/Components/ShootingComponent.h
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Components/ActorComponent.h"
|
||||||
|
#include "Interfaces/Damageable.h"
|
||||||
|
#include "ShootingComponent.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||||
|
class EXO_API UShootingComponent : public UActorComponent
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets default values for this component's properties
|
||||||
|
UShootingComponent();
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float MaxRange = 2000.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category = "Shooting")
|
||||||
|
float DamageValue = 100.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
|
||||||
|
bool bShowDebugLine = true;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Called every frame
|
||||||
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
|
||||||
|
UFUNCTION(Category = "Shooting")
|
||||||
|
void Shoot();
|
||||||
|
|
||||||
|
//UFUNCTION(Category = "Shooting")
|
||||||
|
//void Reload();
|
||||||
|
};
|
||||||
27
Source/Exo/Public/Interfaces/Damageable.h
Normal file
27
Source/Exo/Public/Interfaces/Damageable.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "UObject/Interface.h"
|
||||||
|
#include "Damageable.generated.h"
|
||||||
|
|
||||||
|
// This class does not need to be modified.
|
||||||
|
UINTERFACE(MinimalAPI, Blueprintable)
|
||||||
|
class UDamageable : public UInterface
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class EXO_API IDamageable
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
|
||||||
|
public:
|
||||||
|
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Damage")
|
||||||
|
void TakeDamage(float damageValue);
|
||||||
|
};
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/PlayerController.h"
|
#include "GameFramework/PlayerController.h"
|
||||||
#include <Player/InteractionComponent.h>
|
#include <Player/InteractionComponent.h>
|
||||||
|
#include <Characters/Components/ShootingComponent.h>
|
||||||
#include "ExoPlayerController.generated.h"
|
#include "ExoPlayerController.generated.h"
|
||||||
|
|
||||||
class AExoPlayerCharacter;
|
class AExoPlayerCharacter;
|
||||||
|
|
@ -35,7 +36,7 @@ protected:
|
||||||
void Look(const FInputActionValue& InputActionValue); // MouseXY
|
void Look(const FInputActionValue& InputActionValue); // MouseXY
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void Interact(const FInputActionValue& InputActionValue); // E
|
void Interact(); // E
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Input")
|
UFUNCTION(BlueprintCallable, Category = "Input")
|
||||||
void PlayerJump(); // Space
|
void PlayerJump(); // Space
|
||||||
|
|
@ -125,4 +126,6 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UInteractionComponent* InteractionComponent;
|
UInteractionComponent* InteractionComponent;
|
||||||
|
|
||||||
|
UShootingComponent* ShootingComponent;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user