Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added vertical weapon animation #101

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Content/Maps/warmup.umap
Binary file not shown.
16 changes: 9 additions & 7 deletions Source/Cloud9/Character/Cloud9Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Cloud9/Character/Components/Cloud9CharacterMovement.h"
#include "Cloud9/Character/Components/Cloud9Inventory.h"
#include "Cloud9/Character/Components/Cloud9SpringArmComponent.h"
#include "Cloud9/Tools/Extensions/FVector.h"
#include "Cloud9/Tools/Extensions/TContainer.h"
#include "Cloud9/Weapon/Classes/Cloud9WeaponBase.h"

Expand Down Expand Up @@ -79,7 +80,6 @@ ACloud9Character::ACloud9Character(const FObjectInitializer& ObjectInitializer)

Inventory = CreateDefaultSubobject<UCloud9Inventory>(InventoryComponentName);


// Activate ticking in order to update the cursor every frame.
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
Expand Down Expand Up @@ -122,7 +122,7 @@ void ACloud9Character::UnSneak() const
}
}

void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHitValid) const
void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHitValid)
{
if (IsValid(CursorToWorld))
{
Expand All @@ -136,11 +136,13 @@ void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHit

let Settings = UCloud9DeveloperSettings::Get();

let StartLocation = GetMesh()->GetBoneLocation(CameraTargetBoneName, EBoneSpaces::WorldSpace);

if (Settings->bIsDrawHitCursorLine)
{
DrawDebugLine(
GetWorld(),
GetActorLocation(),
StartLocation,
HitResult.Location,
FColor::Green,
false,
Expand All @@ -162,7 +164,7 @@ void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHit

DrawDebugLine(
GetWorld(),
GetActorLocation(),
StartLocation,
WorldLocation,
FColor::Red,
false,
Expand All @@ -171,9 +173,9 @@ void ACloud9Character::SetViewDirection(const FHitResult& HitResult, bool bIsHit

if (bIsHitValid)
{
let TargetLocation = FVector{HitResult.Location.X, HitResult.Location.Y, 0.0f};
let ActorLocation = GetActorLocation();
let LookRotation = UKismetMathLibrary::FindLookAtRotation(ActorLocation, TargetLocation);
let TargetLocation = HitResult.Location;
let LookRotation = UKismetMathLibrary::FindLookAtRotation(StartLocation, TargetLocation);
ViewVerticalRotation = LookRotation.Pitch;
GetCloud9CharacterMovement()->Rotate({0.0f, LookRotation.Yaw, 0.0f});
}
}
Expand Down
19 changes: 13 additions & 6 deletions Source/Cloud9/Character/Cloud9Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class ACloud9Character : public ACharacter

void UnSneak() const;

void SetViewDirection(const FHitResult& HitResult, bool bIsHitValid) const;
void SetViewDirection(const FHitResult& HitResult, bool bIsHitValid);

UFUNCTION(BlueprintCallable)
float GetViewVerticalRotation() const { return ViewVerticalRotation; }

void SetCameraRotationYaw(float Angle) const;
void AddCameraRotationYaw(float Angle) const;
Expand All @@ -83,28 +86,32 @@ class ACloud9Character : public ACharacter
UPROPERTY(BlueprintReadOnly, Category=Character)
uint32 bIsSneaking : 1;

protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
float ViewVerticalRotation;

private:
// TODO: Move to GameInstance
UPROPERTY(EditDefaultsOnly)
UMaterial* CursorDecal;

/** A decal that projects to the cursor location. */
UPROPERTY(EditDefaultsOnly, Category = Camera, meta=(AllowPrivateAccess))
UPROPERTY(EditDefaultsOnly, Category=Camera, meta=(AllowPrivateAccess))
FName CameraTargetBoneName;

/** Top down camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta=(AllowPrivateAccess))
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera, meta=(AllowPrivateAccess))
UCameraComponent* TopDownCameraComponent;

/** Camera boom positioning the camera above the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta=(AllowPrivateAccess))
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera, meta=(AllowPrivateAccess))
USpringArmComponent* CameraBoom;

/** A decal that projects to the cursor location. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta=(AllowPrivateAccess))
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera, meta=(AllowPrivateAccess))
UDecalComponent* CursorToWorld;

/** An inventory of the character. */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Inventory, meta=(AllowPrivateAccess))
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Inventory, meta=(AllowPrivateAccess))
UCloud9Inventory* Inventory;
};
2 changes: 1 addition & 1 deletion Source/Cloud9/Game/Cloud9DeveloperSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void UCloud9DeveloperSettings::InitializeCVars()
RegisterConsoleVariable(
bIsShowMouseCursor,
TEXT("r.IsShowMouseCursor"),
TEXT("Whether to draw line from character to GetHitUnderCursor point")
TEXT("Whether to draw line from character to GetHitResultUnderCursor point")
);

RegisterConsoleVariable(
Expand Down
2 changes: 1 addition & 1 deletion Source/Cloud9/Weapon/Tables/WeaponCommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct FFirearmCommonData
/**
* Alpha coefficient to fixup hit-scan registration.
*
* GetHitUnderCursor can return value slightly upper then surface.
* GetHitResultUnderCursor can return value slightly upper then surface.
*/
UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category=Settings)
float LineTraceAlpha = 5.0f;
Expand Down