diff --git a/Content/Blueprints/Characters/Enemy/BP_ExoEnemy.uasset b/Content/Blueprints/Characters/Enemy/BP_ExoEnemy.uasset index 085438d..acdb0d9 100644 Binary files a/Content/Blueprints/Characters/Enemy/BP_ExoEnemy.uasset and b/Content/Blueprints/Characters/Enemy/BP_ExoEnemy.uasset differ diff --git a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset index 187dc17..4ba0aa7 100644 Binary files a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset and b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset differ diff --git a/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset b/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset index c48cebd..04d163e 100644 Binary files a/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset and b/Content/Blueprints/Player/Inputs/IMC_ExoMappingContext.uasset differ diff --git a/Content/Levels/TestMap.umap b/Content/Levels/TestMap.umap index 9d75a17..25f5e19 100644 Binary files a/Content/Levels/TestMap.umap and b/Content/Levels/TestMap.umap differ diff --git a/Source/Exo/Private/Characters/Components/ShootingComponent.cpp b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp new file mode 100644 index 0000000..31dc989 --- /dev/null +++ b/Source/Exo/Private/Characters/Components/ShootingComponent.cpp @@ -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()) + { + 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); + + // ... +} + diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index 7417f9d..68803ed 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -29,6 +29,7 @@ void AExoPlayerController::BeginPlay() } InteractionComponent = PlayerCharacter->FindComponentByClass(); + ShootingComponent = PlayerCharacter->FindComponentByClass(); } void AExoPlayerController::PlayerTick(float DeltaTime) @@ -47,6 +48,14 @@ void AExoPlayerController::SetupInputComponent() EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Triggered, this, &AExoPlayerController::Interact); EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Started, this, &AExoPlayerController::PlayerJump); 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) @@ -74,7 +83,7 @@ void AExoPlayerController::Look(const FInputActionValue& InputActionValue) } -void AExoPlayerController::Interact(const FInputActionValue& InputActionValue) +void AExoPlayerController::Interact() { if (InteractionComponent->InteractedActor) IInteractable::Execute_Interact(InteractionComponent->InteractedActor); @@ -123,7 +132,7 @@ void AExoPlayerController::PlayerSprint() void AExoPlayerController::PlayerShoot() { - + ShootingComponent->Shoot(); } void AExoPlayerController::PlayerAim() diff --git a/Source/Exo/Public/Characters/Components/ShootingComponent.h b/Source/Exo/Public/Characters/Components/ShootingComponent.h new file mode 100644 index 0000000..6730a8d --- /dev/null +++ b/Source/Exo/Public/Characters/Components/ShootingComponent.h @@ -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(); +}; diff --git a/Source/Exo/Public/Interfaces/Damageable.h b/Source/Exo/Public/Interfaces/Damageable.h new file mode 100644 index 0000000..92408fc --- /dev/null +++ b/Source/Exo/Public/Interfaces/Damageable.h @@ -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); +}; diff --git a/Source/Exo/Public/Player/ExoPlayerController.h b/Source/Exo/Public/Player/ExoPlayerController.h index 00cf92d..93b3025 100644 --- a/Source/Exo/Public/Player/ExoPlayerController.h +++ b/Source/Exo/Public/Player/ExoPlayerController.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" #include +#include #include "ExoPlayerController.generated.h" class AExoPlayerCharacter; @@ -35,7 +36,7 @@ protected: void Look(const FInputActionValue& InputActionValue); // MouseXY UFUNCTION(BlueprintCallable, Category = "Input") - void Interact(const FInputActionValue& InputActionValue); // E + void Interact(); // E UFUNCTION(BlueprintCallable, Category = "Input") void PlayerJump(); // Space @@ -125,4 +126,6 @@ protected: private: UInteractionComponent* InteractionComponent; + + UShootingComponent* ShootingComponent; };