diff --git a/BP_Pics/Characters/PaperCharacterBase/PaperCharacterBaseGraph.jpg b/BP_Pics/Characters/PaperCharacterBase/PaperCharacterBaseGraph.jpg index a319ffe..13f80bd 100644 Binary files a/BP_Pics/Characters/PaperCharacterBase/PaperCharacterBaseGraph.jpg and b/BP_Pics/Characters/PaperCharacterBase/PaperCharacterBaseGraph.jpg differ diff --git a/GameJamPlus2024/Config/DefaultEditor.ini b/GameJamPlus2024/Config/DefaultEditor.ini index 79b70b5..197e527 100644 --- a/GameJamPlus2024/Config/DefaultEditor.ini +++ b/GameJamPlus2024/Config/DefaultEditor.ini @@ -7,3 +7,5 @@ bReplaceBlueprintWithClass= true bDontLoadBlueprintOutsideEditor= true bBlueprintIsNotBlueprintType= true +[/Script/AdvancedPreviewScene.SharedProfiles] + diff --git a/GameJamPlus2024/Content/Characters/PaperCharacters/PaperCharacterBase.uasset b/GameJamPlus2024/Content/Characters/PaperCharacters/PaperCharacterBase.uasset index 0c3bcc8..fa8c670 100644 Binary files a/GameJamPlus2024/Content/Characters/PaperCharacters/PaperCharacterBase.uasset and b/GameJamPlus2024/Content/Characters/PaperCharacters/PaperCharacterBase.uasset differ diff --git a/GameJamPlus2024/Content/ThirdPerson/Input/Actions/IA_GrapplingHook.uasset b/GameJamPlus2024/Content/ThirdPerson/Input/Actions/IA_GrapplingHook.uasset index 5860985..c0c1bb5 100644 Binary files a/GameJamPlus2024/Content/ThirdPerson/Input/Actions/IA_GrapplingHook.uasset and b/GameJamPlus2024/Content/ThirdPerson/Input/Actions/IA_GrapplingHook.uasset differ diff --git a/GameJamPlus2024/Source/GameJamPlus2024/GameJamPlus2024.Build.cs b/GameJamPlus2024/Source/GameJamPlus2024/GameJamPlus2024.Build.cs index 45278cb..ae8784f 100644 --- a/GameJamPlus2024/Source/GameJamPlus2024/GameJamPlus2024.Build.cs +++ b/GameJamPlus2024/Source/GameJamPlus2024/GameJamPlus2024.Build.cs @@ -6,6 +6,7 @@ public class GameJamPlus2024 : ModuleRules { public GameJamPlus2024(ReadOnlyTargetRules Target) : base(Target) { + PrivateDependencyModuleNames.AddRange(new string[] { "AITestSuite", "AITestSuite", "AITestSuite" }); PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "Paper2D", "Paper2D", "UMGEditor", "UMGEditor" }); diff --git a/GameJamPlus2024/Source/GameJamPlus2024/Private/PaperCharacterBase.cpp b/GameJamPlus2024/Source/GameJamPlus2024/Private/PaperCharacterBase.cpp index 36a89a1..b0c9c80 100644 --- a/GameJamPlus2024/Source/GameJamPlus2024/Private/PaperCharacterBase.cpp +++ b/GameJamPlus2024/Source/GameJamPlus2024/Private/PaperCharacterBase.cpp @@ -7,6 +7,7 @@ #include "EnhancedInputSubsystems.h" #include "EventsManager.h" #include "PaperFlipbookComponent.h" +#include "Camera/CameraComponent.h" #include "GameJamPlus2024/GameJamPlus2024Character.h" #include "Hazards/HazardBase.h" @@ -42,7 +43,11 @@ void APaperCharacterBase::SetupPlayerInputComponent(class UInputComponent* Playe EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping); // Grappling Hook - EnhancedInputComponent->BindAction(GrapplingHookAction, ETriggerEvent::Triggered, GrapplingHookComponent, &UGrapplingHookComponent::LaunchHook); + + //Bind Action, and call the hook launch method in the GrapplingHookComponent passing the mouse position + EnhancedInputComponent->BindAction(GrapplingHookAction, ETriggerEvent::Triggered, GrapplingHookComponent, &UGrapplingHookComponent::LaunchHook); + + //Cast(GetController())->GetMousePosition(MousePosition.X, MousePosition.Y); } else { @@ -127,10 +132,44 @@ void APaperCharacterBase::TakeDamage(int Damage) } +void APaperCharacterBase::EnableMouseEvents() +{ + APlayerController* PC = Cast(GetController()); + + if (PC) + { + PC->bShowMouseCursor = true; + PC->bEnableClickEvents = true; + PC->bEnableMouseOverEvents = true; + } +} + +FVector2D APaperCharacterBase::GetMousePosition() +{ + FVector2D MousePosition(0.0f, 0.0f); + Cast(GetController())->GetMousePosition(MousePosition.X, MousePosition.Y); + return FVector2D(MousePosition); +} + +FVector APaperCharacterBase::ConvertScreenToWorldPoint(const FVector2D& ScreenPosition) +{ + FVector WorldLocation; + FVector WorldDirection = GetActorRightVector(); + APlayerController* PlayerController = Cast(GetController()); + FVector PlayerLocation = PlayerController->GetPawn()->GetActorLocation(); + //UE_LOG(LogTemp, Log, TEXT("Player Location: X = %f, Y = %f, Z = %f"), PlayerLocation.X, PlayerLocation.Y, PlayerLocation.Z); + PlayerController->DeprojectScreenPositionToWorld(ScreenPosition.X, ScreenPosition.Y, WorldLocation,WorldDirection); + + //return FVector(PlayerLocation.X, WorldLocation.X, WorldLocation.Y); + return WorldLocation; +} + void APaperCharacterBase::BeginPlay() { Super::BeginPlay(); OnActorBeginOverlap.AddDynamic(this, &APaperCharacterBase::OnBeginOverlap); + + EnableMouseEvents(); } void APaperCharacterBase::OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor) diff --git a/GameJamPlus2024/Source/GameJamPlus2024/Private/Upgrades/GrapplingHookComponent.cpp b/GameJamPlus2024/Source/GameJamPlus2024/Private/Upgrades/GrapplingHookComponent.cpp index 05dbfd5..fa960dc 100644 --- a/GameJamPlus2024/Source/GameJamPlus2024/Private/Upgrades/GrapplingHookComponent.cpp +++ b/GameJamPlus2024/Source/GameJamPlus2024/Private/Upgrades/GrapplingHookComponent.cpp @@ -3,7 +3,82 @@ #include "Upgrades/GrapplingHookComponent.h" -void UGrapplingHookComponent::LaunchHook() +#include + +#include "DrawDebugHelpers.h" // For visualizing the trace in the editor (optional) +#include "PaperCharacterBase.h" +#include "Camera/CameraComponent.h" +#include "Engine/World.h" // For accessing the world +#include "GameFramework/Actor.h" // For working with actors +#include "Kismet/GameplayStatics.h" +#include "Kismet/KismetSystemLibrary.h" // Optional for advanced tracing + + +void UGrapplingHookComponent::LaunchHook(const FInputActionValue& Value) { - UE_LOG(LogTemp, Warning, TEXT("Hook Launched!")); + APaperCharacterBase* Character = Cast(GetOwner()); + + FHitResult HitResult; // The hit result of the line trace + HookLineTrace(HitResult); // Perform the line trace } + +void UGrapplingHookComponent::HookLineTrace(FHitResult& OutHit) +{ + // UCameraComponent* Camera = GetOwner()->FindComponentByClass(); + // if (!Camera) return; + // + // APaperCharacterBase* Character = Cast(GetOwner()); + // if (!Character) return; + // + // APlayerController* PlayerController = Cast(Character->GetController()); + // if (!PlayerController) return; + // + // FVector2D MousePosition(0.0f, 0.0f); + // Cast(PlayerController)->GetMousePosition(MousePosition.X, MousePosition.Y); + // + // FVector WorldLocation; + // FVector WorldDirection; + // float Distance = 2000.0f; + // + // // Deproject the mouse position to get the world direction + // if (PlayerController->DeprojectMousePositionToWorld(WorldLocation, WorldDirection)) + // { + // // Set the trace start and end points + // FVector Start = Camera->GetComponentTransform().GetLocation(); // The character's location + // FVector End = WorldLocation + (WorldDirection * Distance) ; // Adjust the distance as needed (10,000 units) + // + // ///////// LINE PLANE INTERSECTION + // FVector PlaneOrigin = Character->GetActorLocation(); // A point on the plane (e.g., origin) + // FVector PlaneNormal(1.0f, 0.0f, 0.0f); // The plane's normal (e.g., x-axis) + // /// // Compute the dot product between the line direction and the plane normal + // float Denominator = FVector::DotProduct(PlaneNormal, End); + // + // // Check if the line is parallel to the plane + // if (FMath::IsNearlyZero(Denominator)) { + // return; // No intersection (or line is parallel to the plane) + // } + // + // // Compute the parameter 't' for the intersection point + // float t = FVector::DotProduct(PlaneNormal, PlaneOrigin - Start) / Denominator; + // + // // Compute the intersection point using the parametric line equation + // FVector IntersectionPoint = Start + t * End; + // + // + // /////////// Perform the line trace + // FHitResult HitResult; + // FCollisionQueryParams CollisionParams; + // CollisionParams.AddIgnoredActor(GetOwner()); // Ignore the character itself + // + // bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, PlaneOrigin, IntersectionPoint, ECC_Visibility, CollisionParams); + // + // if (bHit) + // { + // // Handle hit (e.g., log hit actor's name) + // UE_LOG(LogTemp, Warning, TEXT("Hit: %s"), *HitResult.GetActor()->GetName()); + // } + // + // // Optional: Draw debug line for visualization + // DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 4.0f, 0, 1.0f); + // } +} \ No newline at end of file diff --git a/GameJamPlus2024/Source/GameJamPlus2024/Public/PaperCharacterBase.h b/GameJamPlus2024/Source/GameJamPlus2024/Public/PaperCharacterBase.h index fff8113..d7e1198 100644 --- a/GameJamPlus2024/Source/GameJamPlus2024/Public/PaperCharacterBase.h +++ b/GameJamPlus2024/Source/GameJamPlus2024/Public/PaperCharacterBase.h @@ -42,13 +42,14 @@ class GAMEJAMPLUS2024_API APaperCharacterBase : public APaperCharacter public: APaperCharacterBase(); - + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Upgrades", meta = (AllowPrivate)) UDoubleJumpComponent* DoubleJumpComponent; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Upgrades", meta = (AllowPrivate)) UGrapplingHookComponent* GrapplingHookComponent; + protected: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input", meta = (AllowPrivate = "true")) float CameraRotationAngle = 90.0f; @@ -58,12 +59,18 @@ class GAMEJAMPLUS2024_API APaperCharacterBase : public APaperCharacter void SwitchAnimation(const FVector2d& Value); void RotateCamera(const FInputActionValue& Value); void TakeDamage(int Damage); + void EnableMouseEvents(); + // APawn interface virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; // To add mapping context virtual void BeginPlay() override; +public: + FVector2D GetMousePosition(); + FVector ConvertScreenToWorldPoint(const FVector2D& ScreenPosition); + private: UFUNCTION() diff --git a/GameJamPlus2024/Source/GameJamPlus2024/Public/Upgrades/GrapplingHookComponent.h b/GameJamPlus2024/Source/GameJamPlus2024/Public/Upgrades/GrapplingHookComponent.h index 90812a7..a2af8c0 100644 --- a/GameJamPlus2024/Source/GameJamPlus2024/Public/Upgrades/GrapplingHookComponent.h +++ b/GameJamPlus2024/Source/GameJamPlus2024/Public/Upgrades/GrapplingHookComponent.h @@ -14,8 +14,10 @@ UCLASS() class GAMEJAMPLUS2024_API UGrapplingHookComponent : public UCharacterUpgrade { GENERATED_BODY() - -public: - void LaunchHook(); +protected: + void HookLineTrace(FHitResult& OutHit); +public: + void LaunchHook(const FInputActionValue& Value); + };