in the middle of implementing the controller
This commit is contained in:
parent
d91c59aa5c
commit
36bcb08c75
Binary file not shown.
@ -2,6 +2,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Interactable.h"
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "HYPlayerCharacController.generated.h"
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "HYCharacAbilitySystemComponent.h"
|
||||
#include "HYPlayerCharacAttributeSet.h"
|
||||
#include "HYCharacGameplayAbility.h"
|
||||
#include "HYPlayerCharacController.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "Components/InputComponent.h"
|
||||
@ -12,6 +13,9 @@
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Interactable.h"
|
||||
#include "InventoryItem.h"
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -153,6 +157,52 @@ void Ahwanyoung2Character::BeginPlay()
|
||||
}
|
||||
}
|
||||
|
||||
void Ahwanyoung2Character::CheckForInteractables()
|
||||
{
|
||||
// Creates a LineTrace (similar to RayCast) to check for a hit
|
||||
FHitResult HitResult;
|
||||
|
||||
// The range of area the system should check for interactables
|
||||
int32 Range = 500; //this can be changed
|
||||
|
||||
//The start of the trace is the transform of the follow camera
|
||||
FVector StartTrace = FollowCamera->GetComponentLocation();
|
||||
|
||||
//And the end of the trace is the 500 units ahead of the start trace
|
||||
FVector EndTrace = (FollowCamera->GetForwardVector() * Range) + StartTrace;
|
||||
|
||||
//Keeps track of parameters passed into collision function, assuming that
|
||||
//there are multiple collided actors that is passed through the collision function
|
||||
FCollisionQueryParams QueryParams;
|
||||
QueryParams.AddIgnoredActor(this); //we are ignoring this, which is the character
|
||||
|
||||
//Similarly to how GetComponent<>() function works, we get the controller
|
||||
//object attached to the character and cast it as player character controller class
|
||||
AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(GetController());
|
||||
|
||||
if (IController) {
|
||||
//Checking if something is hit by the line cast within the range
|
||||
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace,
|
||||
ECC_Visibility, QueryParams)) {
|
||||
|
||||
//Cast the actor to AInteractable
|
||||
AInteractable* Interactable = Cast<AInteractable>(HitResult.GetActor());
|
||||
|
||||
if (Interactable) {
|
||||
IController->CurrentInteractable = Interactable;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
IController->CurrentInteractable = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Ahwanyoung2Character::Tick(float DeltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Input
|
||||
|
||||
@ -221,65 +271,65 @@ int32 Ahwanyoung2Character::GetAbilityLevel(EAbilityInputID AbilityID) const
|
||||
return int32();
|
||||
}
|
||||
|
||||
void Ahwanyoung2Character::RemoveCharacterAbilities()
|
||||
{
|
||||
//if the object doesn't have the authority, ability system component is not valid
|
||||
//or character abilities are not given in the ability system component,
|
||||
//we don't do anything and just return
|
||||
if (GetLocalRole() != ROLE_Authority ||
|
||||
!AbilitySystemComponent.IsValid() ||
|
||||
!AbilitySystemComponent->CharacterAbilitiesGiven)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//void Ahwanyoung2Character::RemoveCharacterAbilities()
|
||||
//{
|
||||
// //if the object doesn't have the authority, ability system component is not valid
|
||||
// //or character abilities are not given in the ability system component,
|
||||
// //we don't do anything and just return
|
||||
// if (GetLocalRole() != ROLE_Authority ||
|
||||
// !AbilitySystemComponent.IsValid() ||
|
||||
// !AbilitySystemComponent->CharacterAbilitiesGiven)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// TArray<FGameplayAbilitySpecHandle> AbilitiesToRemove;
|
||||
// for (const FGameplayAbilitySpec& Spec : AbilitySystemComponent->GetActivatableAbilities())
|
||||
// {
|
||||
// if (Spec.SourceObject == this && CharacterAbilities.Contains(Spec.Ability->GetClass()))
|
||||
// {
|
||||
// AbilitiesToRemove.Add(Spec.Handle); //spec.handle is an instance of the ability
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (int32 i = 0; i < AbilitiesToRemove.Num(); i++)
|
||||
// {
|
||||
// AbilitySystemComponent->ClearAbility(AbilitiesToRemove[i]);
|
||||
// }
|
||||
//
|
||||
// AbilitySystemComponent->CharacterAbilitiesGiven = false;
|
||||
//}
|
||||
|
||||
TArray<FGameplayAbilitySpecHandle> AbilitiesToRemove;
|
||||
for (const FGameplayAbilitySpec& Spec : AbilitySystemComponent->GetActivatableAbilities())
|
||||
{
|
||||
if (Spec.SourceObject == this && CharacterAbilities.Contains(Spec.Ability->GetClass()))
|
||||
{
|
||||
AbilitiesToRemove.Add(Spec.Handle); //spec.handle is an instance of the ability
|
||||
}
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < AbilitiesToRemove.Num(); i++)
|
||||
{
|
||||
AbilitySystemComponent->ClearAbility(AbilitiesToRemove[i]);
|
||||
}
|
||||
|
||||
AbilitySystemComponent->CharacterAbilitiesGiven = false;
|
||||
}
|
||||
|
||||
void Ahwanyoung2Character::Die()
|
||||
{
|
||||
RemoveCharacterAbilities();
|
||||
|
||||
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||
GetCharacterMovement()->GravityScale = 0;
|
||||
GetCharacterMovement()->Velocity = FVector(0); //disabling character movement when death
|
||||
|
||||
OnCharacterDied.Broadcast(this);
|
||||
|
||||
if (AbilitySystemComponent.IsValid())
|
||||
{
|
||||
AbilitySystemComponent->CancelAbilities();
|
||||
|
||||
FGameplayTagContainer EffectsTagsToRemove;
|
||||
EffectsTagsToRemove.AddTag(EffectRemoveOnDeathTag);
|
||||
int32 NumEffectsRemoved = AbilitySystemComponent->RemoveActiveEffectsWithTags(EffectsTagsToRemove);
|
||||
AbilitySystemComponent->AddLooseGameplayTag(DeadTag);
|
||||
}
|
||||
|
||||
//playing death anim:
|
||||
if (DeathMontage)
|
||||
{
|
||||
PlayAnimMontage(DeathMontage);
|
||||
}
|
||||
else
|
||||
{
|
||||
FinishDying();
|
||||
}
|
||||
}
|
||||
//void Ahwanyoung2Character::Die()
|
||||
//{
|
||||
// RemoveCharacterAbilities();
|
||||
//
|
||||
// GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||
// GetCharacterMovement()->GravityScale = 0;
|
||||
// GetCharacterMovement()->Velocity = FVector(0); //disabling character movement when death
|
||||
//
|
||||
// OnCharacterDied.Broadcast(this);
|
||||
//
|
||||
// if (AbilitySystemComponent.IsValid())
|
||||
// {
|
||||
// AbilitySystemComponent->CancelAbilities();
|
||||
//
|
||||
// FGameplayTagContainer EffectsTagsToRemove;
|
||||
// EffectsTagsToRemove.AddTag(EffectRemoveOnDeathTag);
|
||||
// int32 NumEffectsRemoved = AbilitySystemComponent->RemoveActiveEffectsWithTags(EffectsTagsToRemove);
|
||||
// AbilitySystemComponent->AddLooseGameplayTag(DeadTag);
|
||||
// }
|
||||
//
|
||||
// //playing death anim:
|
||||
// if (DeathMontage)
|
||||
// {
|
||||
// PlayAnimMontage(DeathMontage);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// FinishDying();
|
||||
// }
|
||||
//}
|
||||
|
||||
void Ahwanyoung2Character::FinishDying()
|
||||
{
|
||||
@ -461,3 +511,4 @@ void Ahwanyoung2Character::SetGaugeP(float GaugeP)
|
||||
AttributeSetBase->SetGaugeP(GaugeP);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,11 @@ class Ahwanyoung2Character : public ACharacter, public IAbilitySystemInterface
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class UCameraComponent* FollowCamera;
|
||||
|
||||
/** Collection sphere */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class USphereComponent* CollectionSphere;
|
||||
|
||||
#pragma region Controller
|
||||
/** MappingContext */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
class UInputMappingContext* DefaultMappingContext;
|
||||
@ -44,6 +49,8 @@ class Ahwanyoung2Character : public ACharacter, public IAbilitySystemInterface
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
|
||||
class UInputAction* LookAction;
|
||||
|
||||
#pragma endregion move this to PlayerCharacController.h
|
||||
|
||||
|
||||
|
||||
public:
|
||||
@ -56,10 +63,10 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Hwanyoung|Character")
|
||||
virtual int32 GetAbilityLevel(EAbilityInputID AbilityID) const;
|
||||
|
||||
//this function is called only in the server:
|
||||
virtual void RemoveCharacterAbilities();
|
||||
//this is also called only in the server:
|
||||
virtual void Die();
|
||||
////this function is called only in the server:
|
||||
//virtual void RemoveCharacterAbilities();
|
||||
////this is also called only in the server:
|
||||
//virtual void Die();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Hwanyoung|Character")
|
||||
virtual void FinishDying();
|
||||
@ -102,6 +109,13 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "HY_Character|Camera")
|
||||
FVector GetStartingCameraBoomLocation();
|
||||
|
||||
/** Returns CameraBoom subobject **/
|
||||
class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
|
||||
/** Returns FollowCamera subobject **/
|
||||
class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
|
||||
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
protected:
|
||||
|
||||
//pointers to the attribute set and ability system component
|
||||
@ -139,19 +153,19 @@ protected:
|
||||
FGameplayTag EffectRemoveOnDeathTag;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Character")
|
||||
FText CharacterName;
|
||||
FText CharacterName;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Hwanyoung|Animation")
|
||||
UAnimMontage* DeathMontage;
|
||||
UAnimMontage* DeathMontage;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Abilties")
|
||||
TSubclassOf<class UGameplayEffect> DefaultAttributes;
|
||||
TSubclassOf<class UGameplayEffect> DefaultAttributes;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Abilities")
|
||||
TArray<TSubclassOf<class UGameplayEffect>> StartupEffects;
|
||||
TArray<TSubclassOf<class UGameplayEffect>> StartupEffects;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Hwanyoung|Abilities")
|
||||
TArray<TSubclassOf<class UHYCharacGameplayAbility>> CharacterAbilities;
|
||||
TArray<TSubclassOf<class UHYCharacGameplayAbility>> CharacterAbilities;
|
||||
|
||||
virtual void AddCharacterAbilities();
|
||||
virtual void InitializeAttributes();
|
||||
@ -173,6 +187,9 @@ protected:
|
||||
/** Called for looking input */
|
||||
void Look(const FInputActionValue& Value);
|
||||
|
||||
/** Called for checking for the closest Interactable in sight and in range*/
|
||||
void CheckForInteractables();
|
||||
|
||||
|
||||
protected:
|
||||
// APawn interface
|
||||
@ -181,11 +198,8 @@ protected:
|
||||
// To add mapping context
|
||||
virtual void BeginPlay();
|
||||
|
||||
public:
|
||||
/** Returns CameraBoom subobject **/
|
||||
class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
|
||||
/** Returns FollowCamera subobject **/
|
||||
class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
|
||||
// Checks for the closest Interactable in sight and in range
|
||||
void CheckForInteractables();
|
||||
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user