Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
added somewhat working jump ability
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-gong committed Oct 24, 2020
1 parent c4a1e48 commit 779e75c
Show file tree
Hide file tree
Showing 31 changed files with 48,866 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .idea/.idea.Flopnite/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45,415 changes: 45,415 additions & 0 deletions .idea/.idea.Flopnite/.idea/contentModel.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .idea/.idea.Flopnite/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Flopnite/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Flopnite/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Flopnite/.idea/projectSettingsUpdater.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Flopnite/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2,862 changes: 2,862 additions & 0 deletions .idea/.idea.Flopnite/.idea/workspace.xml

Large diffs are not rendered by default.

344 changes: 344 additions & 0 deletions .idea/.idea.Flopnite/riderModule.iml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Config/DefaultGameplayTags.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ ImportTagsFromConfig=True
WarnOnInvalidTags=True
FastReplication=True
InvalidTagCharacters="\"\',"
+GameplayTagRedirects=(OldTagName="State.Jump",NewTagName="State.Jumping")
+CommonlyReplicatedTags=State.Sprinting
+CommonlyReplicatedTags=State.Jumping
NumBitsForContainerSize=6
NetIndexFirstBitSegment=16
+GameplayTagList=(Tag="Ability.Jump",DevComment="")
+GameplayTagList=(Tag="Ability.Sprint",DevComment="")
+GameplayTagList=(Tag="State.Jumping",DevComment="")
+GameplayTagList=(Tag="State.Sprinting",DevComment="")
Binary file modified Content/AnimStarterPack/BS_Jog.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/AnimStarterPack/Ue4ASP_Character.uasset
Binary file not shown.
Binary file added Content/GameplayAbilities/GA_Jump.uasset
Binary file not shown.
Binary file added Content/GameplayEffects/GE_Jump.uasset
Binary file not shown.
Binary file modified Content/GameplayEffects/GE_Sprint.uasset
Binary file not shown.
Binary file modified Content/ThirdPersonCPP/Blueprints/ThirdPersonCharacter.uasset
Binary file not shown.
Binary file modified Content/ThirdPersonCPP/Maps/ThirdPersonExampleMap.umap
Binary file not shown.
38 changes: 26 additions & 12 deletions Source/Flopnite/Private/FNAnimInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,59 @@
UFNAnimInstance::UFNAnimInstance()
{
/* */
Speed = 0.0f;
IsInAir = false;
Direction = 0.0;
Direction = 0.0f;
Yaw = 0.0f;
Pitch = 0.0f;
JumpEnabled = false;
}

void UFNAnimInstance::NativeUpdateAnimation( float DeltaSeconds )
{
Super::NativeUpdateAnimation( DeltaSeconds );

if ( TryGetPawnOwner() != nullptr )
AFNCharacter * OwningChar = Cast< AFNCharacter >( TryGetPawnOwner() );

if ( OwningChar != nullptr )
{
Speed = TryGetPawnOwner()->GetVelocity().Size();
Direction = CalculateDirection( TryGetPawnOwner()->GetVelocity(), TryGetPawnOwner()->GetActorRotation() );

AFNCharacter * OwningChar = Cast< AFNCharacter >( TryGetPawnOwner() );
if (OwningChar != nullptr)

JumpEnabled = OwningChar->JumpEnabled;
if (JumpEnabled)
{
IsInAir = OwningChar->GetCharacterMovement()->IsFalling();
UE_LOG(LogTemp, Warning, TEXT("jump enabled is true"));
OwningChar->JumpEnabled = false;
}
Speed = OwningChar->GetVelocity().Size();
Direction = CalculateDirection( OwningChar->GetVelocity(), OwningChar->GetActorRotation() );
IsInAir = OwningChar->GetCharacterMovement()->IsFalling();

const FRotator& Delta = OwningChar->GetControlRotation() - OwningChar->GetActorRotation();
const FRotator& AimRotation = FRotator(Pitch, Yaw, 0.0f);

const FRotator& ResultRotation = FMath::RInterpTo(AimRotation, Delta, DeltaSeconds, 15.0f);

Pitch = FMath::ClampAngle(ResultRotation.Pitch, -90, 90);
Yaw = FMath::ClampAngle(ResultRotation.Yaw, -90, 90);
}

}

void UFNAnimInstance::NOTIFY_Jump()
{
AFNCharacter * OwningChar = Cast< AFNCharacter >( TryGetPawnOwner() );

if (EnableJump)
/*if (EnableJump)
{
OwningChar->Jump();
}
}*/

}

void UFNAnimInstance::NOTIFY_JogStart()
{
AFNCharacter * OwningChar = Cast< AFNCharacter >( TryGetPawnOwner() );

EnableJump = false;
//EnableJump = false;

//SomeThing here

Expand Down
27 changes: 3 additions & 24 deletions Source/Flopnite/Private/FNCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ AFNCharacter::AFNCharacter(const class FObjectInitializer& ObjectInitializer) :
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;

bAlwaysRelevant = false; // TODO: should this be true or false?

// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...
GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
Expand All @@ -57,6 +59,7 @@ AFNCharacter::AFNCharacter(const class FObjectInitializer& ObjectInitializer) :
// are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)

ASCInputBound = false;
JumpEnabled = false;
}

//////////////////////////////////////////////////////////////////////////
Expand All @@ -66,8 +69,6 @@ void AFNCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputC
{
// Set up gameplay key bindings
check(PlayerInputComponent);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);

PlayerInputComponent->BindAxis("MoveForward", this, &AFNCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFNCharacter::MoveRight);
Expand All @@ -80,13 +81,6 @@ void AFNCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputC
PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
PlayerInputComponent->BindAxis("LookUpRate", this, &AFNCharacter::LookUpAtRate);

// handle touch devices
PlayerInputComponent->BindTouch(IE_Pressed, this, &AFNCharacter::TouchStarted);
PlayerInputComponent->BindTouch(IE_Released, this, &AFNCharacter::TouchStopped);

// VR headset functionality
PlayerInputComponent->BindAction("ResetVR", IE_Pressed, this, &AFNCharacter::OnResetVR);

BindASCInput();
}

Expand Down Expand Up @@ -141,21 +135,6 @@ UAbilitySystemComponent* AFNCharacter::GetAbilitySystemComponent() const {
}
}

void AFNCharacter::OnResetVR()
{
UHeadMountedDisplayFunctionLibrary::ResetOrientationAndPosition();
}

void AFNCharacter::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
{
Jump();
}

void AFNCharacter::TouchStopped(ETouchIndex::Type FingerIndex, FVector Location)
{
StopJumping();
}

void AFNCharacter::TurnAtRate(float Rate)
{
// calculate delta for this frame from the rate information
Expand Down
2 changes: 1 addition & 1 deletion Source/Flopnite/Private/FNCharacterMovementComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "GameFramework/Character.h"

UFNCharacterMovementComponent::UFNCharacterMovementComponent() {
SprintSpeedMultiplier = 2.0f;
SprintSpeedMultiplier = 1.5f;
RequestToStartSprinting = false;
}

Expand Down
28 changes: 27 additions & 1 deletion Source/Flopnite/Private/FNPlayerState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


#include "FNPlayerState.h"
#include "FNCharacter.h"
#include "FNAbilitySystemComponent.h"
#include "FNAttributeSet.h"

Expand All @@ -16,10 +17,35 @@ AFNPlayerState::AFNPlayerState() {
NetUpdateFrequency = 10.f;
}

void AFNPlayerState::BeginPlay()
{
AbilitySystemComponent->RegisterGameplayTagEvent(FGameplayTag::RequestGameplayTag(FName("Ability.Jump")), EGameplayTagEventType::NewOrRemoved).AddUObject(this, &AFNPlayerState::JumpTagChanged);
}

UAbilitySystemComponent* AFNPlayerState::GetAbilitySystemComponent() const {
return AbilitySystemComponent;
}

UFNAttributeSet* AFNPlayerState::GetAttributeSet() const {
return AttributeSet;
}
}

void AFNPlayerState::JumpTagChanged(const FGameplayTag CallbackTag, int32 NewCount)
{
// new count is greater than zero when the tag is being added
if (NewCount > 0)
{
if (AFNCharacter* OwningChar = CastChecked<AFNCharacter>(GetPawn()))
{
FGameplayTagContainer AbilityTagsToCancel;
AbilityTagsToCancel.AddTag(FGameplayTag::RequestGameplayTag(FName("Ability.Jump")));

FGameplayTagContainer AbilityTagsToIgnore;
UE_LOG(LogTemp, Warning, TEXT("about to cancel abilities"));

AbilitySystemComponent->CancelAbilities(&AbilityTagsToCancel, &AbilityTagsToIgnore);
UE_LOG(LogTemp, Warning, TEXT("jump enabled set to true"));
OwningChar->JumpEnabled = true;
}
}
}
83 changes: 83 additions & 0 deletions Source/Flopnite/Private/GameplayAbilities/JumpAbility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@



#include "GameplayAbilities/JumpAbility.h"
#include "FNAbilitySystemComponent.h"
#include "FNCharacter.h"
#include "FNCharacterMovementComponent.h"

UJumpAbility::UJumpAbility() {
InstancingPolicy = EGameplayAbilityInstancingPolicy::InstancedPerActor;
const FGameplayTag& JumpAbilityTag = FGameplayTag::RequestGameplayTag(FName("Ability.Jump"));
AbilityTags.AddTag(JumpAbilityTag);
ActivationOwnedTags.AddTag(JumpAbilityTag);
AbilityInputID = EFNAbilityInputID::Jump;
}

void UJumpAbility::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData) {
//UE_LOG(LogTemp, Warning, TEXT("ability activated"));
if (HasAuthorityOrPredictionKey(ActorInfo, &ActivationInfo))
{
if (!CommitAbility(Handle, ActorInfo, ActivationInfo))
{
EndAbility(CurrentSpecHandle, CurrentActorInfo, CurrentActivationInfo, true, true);
return;
}

if (AFNCharacter* Character = CastChecked<AFNCharacter>(ActorInfo->AvatarActor.Get())) {

UFNCharacterMovementComponent* CharacterMovementComponent = CastChecked<UFNCharacterMovementComponent>(Character->GetMovementComponent());
if (CharacterMovementComponent) {
if (!JumpEffect)
{
EndAbility(CurrentSpecHandle, CurrentActorInfo, CurrentActivationInfo, true, true);
return;
}
// set jumping gameplay tags
//JumpEffectHandle = ApplyGameplayEffectToOwner(Handle, ActorInfo, ActivationInfo, NewObject<UGameplayEffect>(this, JumpEffect), 1);
// jump
Character->Jump();

return;
}
}

EndAbility(CurrentSpecHandle, CurrentActorInfo, CurrentActivationInfo, true, true);
}
}

bool UJumpAbility::CanActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayTagContainer* SourceTags, const FGameplayTagContainer* TargetTags, OUT FGameplayTagContainer* OptionalRelevantTags) const
{
if (ActorInfo != NULL && ActorInfo->AvatarActor != NULL)
{
ACharacter* Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get());
if (Character && Character->CanJump()) {
return true;
}
}
return false;
}

void UJumpAbility::InputReleased(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo) {
if (ActorInfo != NULL && ActorInfo->AvatarActor != NULL)
{
CancelAbility(Handle, ActorInfo, ActivationInfo, true);
}
}

void UJumpAbility::CancelAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateCancelAbility) {
Super::CancelAbility(Handle, ActorInfo, ActivationInfo, bReplicateCancelAbility);

if (ACharacter * Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get()))
{
//UE_LOG(LogTemp, Warning, TEXT("jump ability cancelled"));
if (JumpEffectHandle.IsValid()) {
// there's a race condition where cancel ability, when called by gameplay tag event function, the jump effect handle is not valid
//UE_LOG(LogTemp, Warning, TEXT("jump effect handle is valid"));
BP_RemoveGameplayEffectFromOwnerWithHandle(JumpEffectHandle);
}

Character->StopJumping();
}
}

16 changes: 5 additions & 11 deletions Source/Flopnite/Private/GameplayAbilities/SprintAbility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

USprintAbility::USprintAbility() {
InstancingPolicy = EGameplayAbilityInstancingPolicy::InstancedPerActor;
FGameplayTag SprintAbilityTag = FGameplayTag::RequestGameplayTag(FName("Ability.Sprint"));
const FGameplayTag& SprintAbilityTag = FGameplayTag::RequestGameplayTag(FName("Ability.Sprint"));
AbilityTags.AddTag(SprintAbilityTag);
ActivationOwnedTags.AddTag(SprintAbilityTag);
AbilityInputID = EFNAbilityInputID::Sprint;
Expand All @@ -23,9 +23,7 @@ void USprintAbility::ActivateAbility(const FGameplayAbilitySpecHandle Handle, co
return;
}

AFNCharacter* Character = CastChecked<AFNCharacter>(ActorInfo->AvatarActor.Get());

if (Character) {
if (AFNCharacter* Character = CastChecked<AFNCharacter>(ActorInfo->AvatarActor.Get())) {

UFNCharacterMovementComponent* CharacterMovementComponent = CastChecked<UFNCharacterMovementComponent>(Character->GetMovementComponent());
if (CharacterMovementComponent) {
Expand All @@ -52,8 +50,7 @@ bool USprintAbility::CanActivateAbility(const FGameplayAbilitySpecHandle Handle,
{
if (ActorInfo != NULL && ActorInfo->AvatarActor != NULL)
{
ACharacter* Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get());
if (Character) {
if (ACharacter* Character = CastChecked<ACharacter>(ActorInfo->AvatarActor.Get())) {
UFNCharacterMovementComponent* CharacterMovementComponent = CastChecked<UFNCharacterMovementComponent>(Character->GetMovementComponent());
if (CharacterMovementComponent && !CharacterMovementComponent->IsFalling()) {
return true;
Expand All @@ -74,12 +71,9 @@ void USprintAbility::CancelAbility(const FGameplayAbilitySpecHandle Handle, cons
// set a sprinting flag in character movement component to false
Super::CancelAbility(Handle, ActorInfo, ActivationInfo, bReplicateCancelAbility);

AFNCharacter* Character = CastChecked<AFNCharacter>(ActorInfo->AvatarActor.Get());

if (Character) {
if (AFNCharacter* Character = CastChecked<AFNCharacter>(ActorInfo->AvatarActor.Get())) {

UFNCharacterMovementComponent* CharacterMovementComponent = CastChecked<UFNCharacterMovementComponent>(Character->GetMovementComponent());
if (CharacterMovementComponent) {
if (UFNCharacterMovementComponent* CharacterMovementComponent = CastChecked<UFNCharacterMovementComponent>(Character->GetMovementComponent())) {
// set sprinting gameplay tags
if (SprintEffectHandle.IsValid()) {
BP_RemoveGameplayEffectFromOwnerWithHandle(SprintEffectHandle);
Expand Down
3 changes: 2 additions & 1 deletion Source/Flopnite/Public/FNAbilitySystemComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ enum class EFNAbilityInputID : uint8
None UMETA(DisplayName = "None"),
Confirm UMETA(DisplayName = "Confirm"),
Cancel UMETA(DisplayName = "Cancel"),
Sprint UMETA(DisplayName = "Sprint") // shift
Sprint UMETA(DisplayName = "Sprint"), // shift
Jump UMETA(DisplayName = "Jump") // space
};

UCLASS()
Expand Down
Loading

0 comments on commit 779e75c

Please sign in to comment.