commit 8c1bfa9f759491011e405e508cab1e6295835be3 Author: theOneEmployee <50168768+theOneEmployee@users.noreply.github.com> Date: Thu Oct 8 15:33:58 2020 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4334a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +Binaries +DerivedDataCache +Intermediate +Saved +.vscode +.vs +*.VC.db +*.opensdf +*.opendb +*.sdf +*.sln +*.suo +*.xcodeproj +*.xcworkspace \ No newline at end of file diff --git a/BuildingEscape.uproject b/BuildingEscape.uproject new file mode 100644 index 0000000..2c6f972 --- /dev/null +++ b/BuildingEscape.uproject @@ -0,0 +1,17 @@ +{ + "FileVersion": 3, + "EngineAssociation": "4.22", + "Category": "", + "Description": "", + "Enterprise": true, + "Modules": [ + { + "Name": "BuildingEscape", + "Type": "Runtime", + "LoadingPhase": "Default", + "AdditionalDependencies": [ + "Engine" + ] + } + ] +} \ No newline at end of file diff --git a/Config/DefaultEditor.ini b/Config/DefaultEditor.ini new file mode 100644 index 0000000..139597f --- /dev/null +++ b/Config/DefaultEditor.ini @@ -0,0 +1,2 @@ + + diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini new file mode 100644 index 0000000..fdd5719 --- /dev/null +++ b/Config/DefaultEngine.ini @@ -0,0 +1,63 @@ +[URL] +[/Script/Engine.RendererSettings] +r.DefaultFeature.AutoExposure.ExtendDefaultLuminanceRange=True + +[/Script/HardwareTargeting.HardwareTargetingSettings] +TargetedHardwareClass=Desktop +AppliedTargetedHardwareClass=Desktop +DefaultGraphicsPerformance=Maximum +AppliedDefaultGraphicsPerformance=Maximum + +[/Script/EngineSettings.GameMapsSettings] +EditorStartupMap=/Game/Levels/BuildingEscape.BuildingEscape +GameDefaultMap=/Game/Levels/BuildingEscape.BuildingEscape +GlobalDefaultGameMode=/Game/Blueprints/MyBuildingEscapeGameModeBase_BP.MyBuildingEscapeGameModeBase_BP_C + +[/Script/Engine.Engine] +bUseFixedFrameRate=True +FixedFrameRate=60.000000 + +[/Script/Engine.PhysicsSettings] +DefaultGravityZ=-980.000000 +DefaultTerminalVelocity=4000.000000 +DefaultFluidFriction=0.300000 +SimulateScratchMemorySize=262144 +RagdollAggregateThreshold=4 +TriangleMeshTriangleMinAreaThreshold=5.000000 +bEnableShapeSharing=False +bEnablePCM=True +bEnableStabilization=False +bWarnMissingLocks=True +bEnable2DPhysics=False +PhysicErrorCorrection=(PingExtrapolation=0.100000,PingLimit=100.000000,ErrorPerLinearDifference=1.000000,ErrorPerAngularDifference=1.000000,MaxRestoredStateError=1.000000,MaxLinearHardSnapDistance=400.000000,PositionLerp=0.000000,AngleLerp=0.400000,LinearVelocityCoefficient=100.000000,AngularVelocityCoefficient=10.000000,ErrorAccumulationSeconds=0.500000,ErrorAccumulationDistanceSq=15.000000,ErrorAccumulationSimilarity=100.000000) +LockedAxis=Invalid +DefaultDegreesOfFreedom=Full3D +BounceThresholdVelocity=200.000000 +FrictionCombineMode=Average +RestitutionCombineMode=Average +MaxAngularVelocity=3600.000000 +MaxDepenetrationVelocity=0.000000 +ContactOffsetMultiplier=0.020000 +MinContactOffset=2.000000 +MaxContactOffset=8.000000 +bSimulateSkeletalMeshOnDedicatedServer=True +DefaultShapeComplexity=CTF_UseSimpleAndComplex +bDefaultHasComplexCollision=True +bSuppressFaceRemapTable=False +bSupportUVFromHitResults=False +bDisableActiveActors=False +bDisableKinematicStaticPairs=False +bDisableKinematicKinematicPairs=False +bDisableCCD=False +bEnableEnhancedDeterminism=False +MaxPhysicsDeltaTime=0.033333 +bSubstepping=False +bSubsteppingAsync=False +MaxSubstepDeltaTime=0.016667 +MaxSubsteps=6 +SyncSceneSmoothingFactor=0.000000 +InitialAverageFrameRate=0.016667 +PhysXTreeRebuildRate=10 +DefaultBroadphaseSettings=(bUseMBPOnClient=False,bUseMBPOnServer=False,MBPBounds=(Min=(X=0.000000,Y=0.000000,Z=0.000000),Max=(X=0.000000,Y=0.000000,Z=0.000000),IsValid=0),MBPNumSubdivs=2) + + diff --git a/Config/DefaultGame.ini b/Config/DefaultGame.ini new file mode 100644 index 0000000..5270598 --- /dev/null +++ b/Config/DefaultGame.ini @@ -0,0 +1,2 @@ +[/Script/EngineSettings.GeneralProjectSettings] +ProjectID=ACCA80D7484FF60AFDD85690697A2DA6 diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini new file mode 100644 index 0000000..22e2191 --- /dev/null +++ b/Config/DefaultInput.ini @@ -0,0 +1,52 @@ + +[/Script/Engine.InputSettings] +-AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f)) +-AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) +-AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f)) ++AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MouseWheelAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_LeftTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_RightTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Left_TriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Left_Grip1Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Left_Grip2Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Right_TriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Right_Grip1Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="MotionController_Right_Grip2Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_Special_Left_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) ++AxisConfig=(AxisKeyName="Gamepad_Special_Left_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False)) +bAltEnterTogglesFullscreen=True +bF11TogglesFullscreen=True +bUseMouseForTouch=False +bEnableMouseSmoothing=True +bEnableFOVScaling=True +bCaptureMouseOnLaunch=True +bDefaultViewportMouseLock=False +bAlwaysShowTouchInterface=False +bShowConsoleOnFourFingerTap=True +bEnableGestureRecognizer=False +bUseAutocorrect=False +DefaultViewportMouseCaptureMode=CapturePermanently_IncludingInitialMouseDown +DefaultViewportMouseLockMode=LockOnCapture +FOVScale=0.011110 +DoubleClickTime=0.200000 ++ActionMappings=(ActionName="Grab",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton) +DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks +ConsoleKey=None +-ConsoleKeys=Tilde ++ConsoleKeys=Tilde ++ConsoleKeys=Caret + + diff --git a/Content/Blueprints/DefaultPawn_BP.uasset b/Content/Blueprints/DefaultPawn_BP.uasset new file mode 100644 index 0000000..e89d4d3 Binary files /dev/null and b/Content/Blueprints/DefaultPawn_BP.uasset differ diff --git a/Content/Blueprints/MyBuildingEscapeGameModeBase_BP.uasset b/Content/Blueprints/MyBuildingEscapeGameModeBase_BP.uasset new file mode 100644 index 0000000..8f4f733 Binary files /dev/null and b/Content/Blueprints/MyBuildingEscapeGameModeBase_BP.uasset differ diff --git a/Content/Levels/BuildingEscape.umap b/Content/Levels/BuildingEscape.umap new file mode 100644 index 0000000..4fe81ae Binary files /dev/null and b/Content/Levels/BuildingEscape.umap differ diff --git a/Content/Levels/BuildingEscape_BuiltData.uasset b/Content/Levels/BuildingEscape_BuiltData.uasset new file mode 100644 index 0000000..8adf701 Binary files /dev/null and b/Content/Levels/BuildingEscape_BuiltData.uasset differ diff --git a/Content/Models/MI_Broken_Concrete_Floor.uasset b/Content/Models/MI_Broken_Concrete_Floor.uasset new file mode 100644 index 0000000..9b495e7 Binary files /dev/null and b/Content/Models/MI_Broken_Concrete_Floor.uasset differ diff --git a/Content/Models/MI_Door_Frame_Broken_Concrete.uasset b/Content/Models/MI_Door_Frame_Broken_Concrete.uasset new file mode 100644 index 0000000..f9cd779 Binary files /dev/null and b/Content/Models/MI_Door_Frame_Broken_Concrete.uasset differ diff --git a/Content/Models/MI_Metal_Wood_Ceiling.uasset b/Content/Models/MI_Metal_Wood_Ceiling.uasset new file mode 100644 index 0000000..9db5576 Binary files /dev/null and b/Content/Models/MI_Metal_Wood_Ceiling.uasset differ diff --git a/Content/Models/M_Brass.uasset b/Content/Models/M_Brass.uasset new file mode 100644 index 0000000..6cb5913 Binary files /dev/null and b/Content/Models/M_Brass.uasset differ diff --git a/Content/Models/M_Broken_Concrete.uasset b/Content/Models/M_Broken_Concrete.uasset new file mode 100644 index 0000000..db0c389 Binary files /dev/null and b/Content/Models/M_Broken_Concrete.uasset differ diff --git a/Content/Models/M_Broken_Concrete_Floor.uasset b/Content/Models/M_Broken_Concrete_Floor.uasset new file mode 100644 index 0000000..35e78c1 Binary files /dev/null and b/Content/Models/M_Broken_Concrete_Floor.uasset differ diff --git a/Content/Models/M_MetalWood.uasset b/Content/Models/M_MetalWood.uasset new file mode 100644 index 0000000..03addd2 Binary files /dev/null and b/Content/Models/M_MetalWood.uasset differ diff --git a/Content/Models/M_MetalWood_Inst.uasset b/Content/Models/M_MetalWood_Inst.uasset new file mode 100644 index 0000000..5157815 Binary files /dev/null and b/Content/Models/M_MetalWood_Inst.uasset differ diff --git a/Content/Models/SM_DoorFrame.uasset b/Content/Models/SM_DoorFrame.uasset new file mode 100644 index 0000000..93c790c Binary files /dev/null and b/Content/Models/SM_DoorFrame.uasset differ diff --git a/Content/Models/SM_Door_OLD.uasset b/Content/Models/SM_Door_OLD.uasset new file mode 100644 index 0000000..e3ca20d Binary files /dev/null and b/Content/Models/SM_Door_OLD.uasset differ diff --git a/Content/Models/T_Concrete_AO.uasset b/Content/Models/T_Concrete_AO.uasset new file mode 100644 index 0000000..36b711d Binary files /dev/null and b/Content/Models/T_Concrete_AO.uasset differ diff --git a/Content/Models/T_Concrete_BC.uasset b/Content/Models/T_Concrete_BC.uasset new file mode 100644 index 0000000..965b6ef Binary files /dev/null and b/Content/Models/T_Concrete_BC.uasset differ diff --git a/Content/Models/T_Concrete_N.uasset b/Content/Models/T_Concrete_N.uasset new file mode 100644 index 0000000..ec0bb7b Binary files /dev/null and b/Content/Models/T_Concrete_N.uasset differ diff --git a/Content/Models/T_Concrete_R.uasset b/Content/Models/T_Concrete_R.uasset new file mode 100644 index 0000000..5a7e6e7 Binary files /dev/null and b/Content/Models/T_Concrete_R.uasset differ diff --git a/Content/Models/T_MetalWood.uasset b/Content/Models/T_MetalWood.uasset new file mode 100644 index 0000000..8182965 Binary files /dev/null and b/Content/Models/T_MetalWood.uasset differ diff --git a/Content/Models/Volumes/TriggerVolume_StaticMesh.uasset b/Content/Models/Volumes/TriggerVolume_StaticMesh.uasset new file mode 100644 index 0000000..70a98c9 Binary files /dev/null and b/Content/Models/Volumes/TriggerVolume_StaticMesh.uasset differ diff --git a/Content/Sounds/door-lock.uasset b/Content/Sounds/door-lock.uasset new file mode 100644 index 0000000..14446c9 Binary files /dev/null and b/Content/Sounds/door-lock.uasset differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..9497fb1 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# BuildingEscape + +Developed with Unreal Engine 4 diff --git a/Source/BuildingEscape.Target.cs b/Source/BuildingEscape.Target.cs new file mode 100644 index 0000000..f15f42c --- /dev/null +++ b/Source/BuildingEscape.Target.cs @@ -0,0 +1,14 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +using UnrealBuildTool; +using System.Collections.Generic; + +public class BuildingEscapeTarget : TargetRules +{ + public BuildingEscapeTarget(TargetInfo Target) : base(Target) + { + Type = TargetType.Game; + + ExtraModuleNames.AddRange( new string[] { "BuildingEscape" } ); + } +} diff --git a/Source/BuildingEscape/BuildingEscape.Build.cs b/Source/BuildingEscape/BuildingEscape.Build.cs new file mode 100644 index 0000000..a3b3293 --- /dev/null +++ b/Source/BuildingEscape/BuildingEscape.Build.cs @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +using UnrealBuildTool; + +public class BuildingEscape : ModuleRules +{ + public BuildingEscape(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); + + PrivateDependencyModuleNames.AddRange(new string[] { }); + + // Uncomment if you are using Slate UI + // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); + + // Uncomment if you are using online features + // PrivateDependencyModuleNames.Add("OnlineSubsystem"); + + // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true + } +} diff --git a/Source/BuildingEscape/BuildingEscape.cpp b/Source/BuildingEscape/BuildingEscape.cpp new file mode 100644 index 0000000..a8b4e86 --- /dev/null +++ b/Source/BuildingEscape/BuildingEscape.cpp @@ -0,0 +1,6 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "BuildingEscape.h" +#include "Modules/ModuleManager.h" + +IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, BuildingEscape, "BuildingEscape" ); diff --git a/Source/BuildingEscape/BuildingEscape.h b/Source/BuildingEscape/BuildingEscape.h new file mode 100644 index 0000000..90aad9e --- /dev/null +++ b/Source/BuildingEscape/BuildingEscape.h @@ -0,0 +1,6 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" + diff --git a/Source/BuildingEscape/BuildingEscapeGameModeBase.cpp b/Source/BuildingEscape/BuildingEscapeGameModeBase.cpp new file mode 100644 index 0000000..5326b8b --- /dev/null +++ b/Source/BuildingEscape/BuildingEscapeGameModeBase.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BuildingEscapeGameModeBase.h" + diff --git a/Source/BuildingEscape/BuildingEscapeGameModeBase.h b/Source/BuildingEscape/BuildingEscapeGameModeBase.h new file mode 100644 index 0000000..2271e5d --- /dev/null +++ b/Source/BuildingEscape/BuildingEscapeGameModeBase.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "BuildingEscapeGameModeBase.generated.h" + +/** + * + */ +UCLASS() +class BUILDINGESCAPE_API ABuildingEscapeGameModeBase : public AGameModeBase +{ + GENERATED_BODY() + +}; diff --git a/Source/BuildingEscape/Grabber.cpp b/Source/BuildingEscape/Grabber.cpp new file mode 100644 index 0000000..3c8d67a --- /dev/null +++ b/Source/BuildingEscape/Grabber.cpp @@ -0,0 +1,181 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "DrawDebugHelpers.h" +#include "Engine/World.h" +#include "GameFramework/PlayerController.h" +#include "PhysicsEngine/PhysicsHandleComponent.h" +#include "Grabber.h" + +#define OUT //mark for outparameters (only for reading purposes) +// Sets default values for this component's properties +UGrabber::UGrabber() +{ + // 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 UGrabber::BeginPlay() +{ + Super::BeginPlay(); + + FindPhysicsHandle(); //Check for physics Handle Component + + SetupInputComponent(); +} + +void UGrabber::FindPhysicsHandle() +{ + PhysicsHandle = GetOwner()->FindComponentByClass(); //<> for function templates + if(!PhysicsHandle) // same as if(PhysicsHandle == nullptr) + { + UE_LOG(LogTemp, Error, TEXT("No Physics handle component found on: %s !"), *GetOwner()->GetName()); + } +} + +void UGrabber::SetupInputComponent() +{ + InputComponent = GetOwner()->FindComponentByClass(); + if(InputComponent) + { + //UE_LOG(LogTemp, Warning, TEXT("Input Component found on: %s !"), *GetOwner()->GetName()); + InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab); // User Input zu einem funktionsaufruf binden // Name der funktion beim keypress gleich name vom action in projectsettings , IE = InputEvent + InputComponent->BindAction("Grab", IE_Released, this, &UGrabber::GrabRelease); + } + else + { + UE_LOG(LogTemp, Error, TEXT("Input Component MISSING on: %s !"), *GetOwner()->GetName()); + } +} + +void UGrabber::Grab() +{ + //only Raycast, when key is pressed and Try and reach any actor with physics body collision set. + FHitResult HitResult = GetFirstPhysicsBodyInReach(); + UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent(); + AActor* ActorHit = HitResult.GetActor(); + + //if we hit something, attach physics handle + if(ActorHit) //if an actor is hit, then attach PhysicsHandle + { + if(!PhysicsHandle){return;} + PhysicsHandle->GrabComponentAtLocation + ( + ComponentToGrab, + NAME_None, + GetLineTraceEnd() + ); + } + +} + +void UGrabber::GrabRelease() +{ + //Remove, release physicshandle + if(!PhysicsHandle){return;} + PhysicsHandle->ReleaseComponent(); +} + +// Called every frame +void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + if(!PhysicsHandle){return;} + //If PhysicsBody attached + if(PhysicsHandle->GrabbedComponent) + { + //move object we are holding + PhysicsHandle->SetTargetLocation(GetLineTraceEnd()); + } +} + +FHitResult UGrabber::GetFirstPhysicsBodyInReach() const +{ + FHitResult Hit; + //Raycast out to a certain distance (Reach) + FCollisionQueryParams TraceParams(FName(TEXT("")), false, GetOwner()); //fname, ComplexCollision=false, ignore hit on owner(origin point) + + GetWorld()->LineTraceSingleByObjectType( + OUT Hit, + GetPlayerWorldPosition(), //PlayerViewPointLocation + GetLineTraceEnd(), + FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), //:: to accsess an enum + TraceParams + ); + return Hit; +} + +FVector UGrabber::GetPlayerWorldPosition() const +{ + //Get Player Viewport + FVector PlayerViewPointLocation; + FRotator PlayerViewPointRotation; + GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint( + OUT PlayerViewPointLocation, + OUT PlayerViewPointRotation + ); + + return PlayerViewPointLocation; +} + +FVector UGrabber::GetLineTraceEnd() const //Players Reach +{ + //Get Player Viewport + FVector PlayerViewPointLocation; + FRotator PlayerViewPointRotation; + GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint( + OUT PlayerViewPointLocation, + OUT PlayerViewPointRotation + ); + + return PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach; +} + +//comments +//Logging out to test + // UE_LOG(LogTemp, Warning, TEXT("Location: %s, Rotation= %s"), + // *PlayerViewPointLocation.ToString(), + // *PlayerViewPointRotation.ToString() + // ); + + /* + //Get Player Viewport + FVector PlayerViewPointLocation; + FRotator PlayerViewPointRotation; + GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint( + OUT PlayerViewPointLocation, + OUT PlayerViewPointRotation + ); + + //GetPhysicsbodyInReach + //Draw a Line from the Player showing the Reach + FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach; + // DEBUG + // DrawDebugLine( + // GetWorld(), + // PlayerViewPointLocation, + // LineTraceEnd, + // FColor(0, 255 , 0) //red, green, blue, + // false, + // 0.f, + // 0, + // 5.f + // ); + */ + + //return name of hit actor + //See what it hits + // if(Hit.GetActor()) + // UE_LOG(LogTemp, Warning, TEXT("Hit: %s"), *Hit.GetActor()->GetName()); + //or + /* + AActor* ActorHit = Hit.GetActor(); + + //Log out to Test + if(Hit.GetActor()) + { + UE_LOG(LogTemp, Warning, TEXT("Hit: %s"), *ActorHit->GetName()); + } + */ \ No newline at end of file diff --git a/Source/BuildingEscape/Grabber.h b/Source/BuildingEscape/Grabber.h new file mode 100644 index 0000000..03f6a86 --- /dev/null +++ b/Source/BuildingEscape/Grabber.h @@ -0,0 +1,50 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "PhysicsEngine/PhysicsHandleComponent.h" +#include "Grabber.generated.h" + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class BUILDINGESCAPE_API UGrabber : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UGrabber(); + + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +private: + UPROPERTY(EditAnywhere) + float Reach = 100.f; + + UPROPERTY() //Everything with a U has a UPROPERTY + UPhysicsHandleComponent* PhysicsHandle = nullptr; //protection against crashes + + UPROPERTY() + UInputComponent* InputComponent = nullptr; + + void Grab(); + void GrabRelease(); + void FindPhysicsHandle(); + void SetupInputComponent(); + + //return the first Actor in Reach with physicsbody + FHitResult GetFirstPhysicsBodyInReach() const; + + //Return Players Line Trace End + FVector GetLineTraceEnd() const; // playersReach + + //Get Players Position in the World + FVector GetPlayerWorldPosition() const; +}; diff --git a/Source/BuildingEscape/OpenDoor.cpp b/Source/BuildingEscape/OpenDoor.cpp new file mode 100644 index 0000000..074357a --- /dev/null +++ b/Source/BuildingEscape/OpenDoor.cpp @@ -0,0 +1,157 @@ +// Fill out your copyright notice in the Description page of Project Settings. +#include "OpenDoor.h" +#include "Components/AudioComponent.h" +#include "Components/PrimitiveComponent.h" +#include "Engine/World.h" +#include "GameFramework/Actor.h" +#include "GameFramework/PlayerController.h" + +#define OUT + +// Sets default values for this component's properties +UOpenDoor::UOpenDoor() +{ + // 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 UOpenDoor::BeginPlay() +{ + Super::BeginPlay(); + + InitialYaw = GetOwner()->GetActorRotation().Yaw; + CurrentYaw = InitialYaw; + TargetAngleOfOpenDoor += InitialYaw; + + FindPressurePlateComponent(); + + FindAudioComponent(); + //ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn(); +} + +void UOpenDoor::FindAudioComponent() +{ + AudioComponent = GetOwner()->FindComponentByClass(); //<> for function templates + if(!AudioComponent) // same as if(PhysicsHandle == nullptr) + { + UE_LOG(LogTemp, Error, TEXT("No Audio component found on: %s !"), *GetOwner()->GetName()); + } +} + +void UOpenDoor::FindPressurePlateComponent() +{ + if(!PressurePlate) + { + UE_LOG(LogTemp, Error, TEXT("%s has OpenDoor on it, but no PressurePlate set!"), *GetOwner()->GetName()); + } +} + +// Called every frame +void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... + //if(PressurePlate->IsOverlappingActor(ActorThatOpens)) // kann nullpointer + UE4 crash geben + //if(PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens)) //prüft erst, ob es ein actor gibt + if(TotalMass() > MassToOpenDoor) + { + OpenDoor(DeltaTime); + //DoorLastOpened When the door was opened + DoorLastOpened = GetWorld()->GetTimeSeconds();; + } + + else + { + //if door has been open longer than DoorCloseDelay + //if(GetWorld()->GetTimeSeconds() > DoorLastOpened + DoorDelay) + if(GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorDelay) + CloseDoor(DeltaTime); + } +} + +void UOpenDoor::OpenDoor(float DeltaTime) +{ + FRotator DoorRotation = GetOwner()->GetActorRotation(); + //CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2.f); + CurrentYaw = FMath::Lerp(CurrentYaw, TargetAngleOfOpenDoor, DeltaTime * OpenDoorRotationSpeed); //complex Interpolation + DoorRotation.Yaw = CurrentYaw; + GetOwner()->SetActorRotation(DoorRotation); + + CloseDoorSoundHasBeenPlayed = false; + if(!AudioComponent){return;} + if(!OpenDoorSoundHasBeenPlayed) + { + AudioComponent->Play(); + OpenDoorSoundHasBeenPlayed = true; + } +} + +void UOpenDoor::CloseDoor(float DeltaTime) +{ + FRotator DoorRotation = GetOwner()->GetActorRotation(); + CurrentYaw = FMath::Lerp(CurrentYaw, InitialYaw, DeltaTime * CloseDoorRotationSpeed); + DoorRotation.Yaw = CurrentYaw; + GetOwner()->SetActorRotation(DoorRotation); + + OpenDoorSoundHasBeenPlayed = false; + if(!AudioComponent){return;} + if(!CloseDoorSoundHasBeenPlayed) + { + AudioComponent->Play(); + CloseDoorSoundHasBeenPlayed = true; + } +} + +float UOpenDoor::TotalMass() const +{ + float TotalMass = 0.f; + + //find All Overlapping Actors + TArray OverlapingActors; + + if (!PressurePlate){return TotalMass;} + PressurePlate->GetOverlappingActors(OUT OverlapingActors); + + //Add Up Their Masses + for(AActor* Actor : OverlapingActors) + { + TotalMass += Actor -> FindComponentByClass()->GetMass(); + UE_LOG(LogTemp, Warning, TEXT("%s is on the pressureplate"), *Actor->GetName()); + } + + return TotalMass; +} + +//Notes + //UE_LOG(LogTemp, Warning, TEXT("%f"), TargetYaw); + // UE_LOG(LogTemp, Warning, TEXT("%s"), *GetOwner()->GetActorRotation().ToString()); + // UE_LOG(LogTemp, Warning, TEXT("The Yaw is: %f"), GetOwner()->GetActorRotation().Yaw); + + // FRotator CurrentRotation = GetOwner()->GetActorRotation(); + // FMath::Lerp(CurrentRotation, FRotator(0.f,90.f,0.f), 0.2f); + + // GetOwner()->SetActorRotation(CurrentRotation); + // UE_LOG(LogTemp, Warning, TEXT("The Yaw is: %f"), CurrentRotation.Yaw); + //TargetYaw = 90.f; + // FRotator OpenDoor(0.f, 0.f, 0.f); + // //OpenDoor.Yaw = FMath::Lerp(CurrentYaw, TargetYaw, 0.02f); //complex Interpolation + // OpenDoor.Yaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2.f);//complex Interpolation Framerate unabhängig wegen Deltatime + // //OpenDoor.Yaw = FMath::FInterpConstantTo(CurrentYaw, TargetYaw, DeltaTime, 0.02f); //lineare interpolation + // GetOwner()->SetActorRotation(OpenDoor); + + + + //float f = 10.f; + //FRotator CurrentRotation = GetOwner()->GetActorRotation(); + //FRotator Rotation = FRotator(0.f, -90.f, 0.f); + //FRotator OpenDoor={float,float,float} + //FRotator OpenDoor{float,float,float} + //FRotator OpenDoor(float,float,float) + //CurrentRotation.Yaw = 90.f; + + //GetOwner()->SetActorRotation(CurrentRotation); \ No newline at end of file diff --git a/Source/BuildingEscape/OpenDoor.h b/Source/BuildingEscape/OpenDoor.h new file mode 100644 index 0000000..ff725ed --- /dev/null +++ b/Source/BuildingEscape/OpenDoor.h @@ -0,0 +1,71 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/AudioComponent.h" +#include "Components/ActorComponent.h" +#include "Engine/TriggerVolume.h" +//#include "Engine/ActorChannel.h" +#include "OpenDoor.generated.h" + + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class BUILDINGESCAPE_API UOpenDoor : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UOpenDoor(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + void OpenDoor(float DeltaTime); + void CloseDoor(float DeltaTime); + float TotalMass() const; + void FindAudioComponent(); + void FindPressurePlateComponent(); + + //Tracks if Sound has been Played + bool OpenDoorSoundHasBeenPlayed = false; + bool CloseDoorSoundHasBeenPlayed = true; + +private: + + float InitialYaw; + float CurrentYaw; + float DoorLastOpened = 0.f; + bool HasSoundBeenPlayed = false; + + UPROPERTY(EditAnywhere) + float MassToOpenDoor = 50.f; + + UPROPERTY(EditAnywhere) + float TargetAngleOfOpenDoor =90.f; + + UPROPERTY(EditAnywhere) + float OpenDoorRotationSpeed = 2.f; + + UPROPERTY(EditAnywhere) + float CloseDoorRotationSpeed = 0.5f; + + UPROPERTY(EditAnywhere) + float DoorDelay = 2.f; //2 second delay + + UPROPERTY(EditAnywhere) + ATriggerVolume* PressurePlate = nullptr; + + UPROPERTY(EditAnywhere) + AActor* ActorThatOpens = nullptr; + + UPROPERTY() + UAudioComponent* AudioComponent = nullptr; + +}; diff --git a/Source/BuildingEscape/WorldPosition.cpp b/Source/BuildingEscape/WorldPosition.cpp new file mode 100644 index 0000000..38a5a49 --- /dev/null +++ b/Source/BuildingEscape/WorldPosition.cpp @@ -0,0 +1,63 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "WorldPosition.h" +#include "GameFramework/Actor.h" + +// Sets default values for this component's properties +UWorldPosition::UWorldPosition() +{ + // 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 UWorldPosition::BeginPlay() +{ + Super::BeginPlay(); + + // ... + FString ObjectName = GetOwner()->GetName(); + FString ObjectPosition = GetOwner()->GetActorLocation().ToString(); + + UE_LOG(LogTemp, Warning, TEXT("%s"), *ObjectName); + UE_LOG(LogTemp, Warning, TEXT("%s"), *ObjectPosition); + + UE_LOG(LogTemp, Warning, TEXT("My name is: %s"), *GetOwner()->GetName()); + UE_LOG(LogTemp, Warning, TEXT("My worldPosition is: %s"), *GetOwner()->GetActorLocation().ToString()); + +} + + +// Called every frame +void UWorldPosition::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + +//comment +//part 1 + +// UE_LOG(LogTemp, Warning, TEXT("This is a Warning")); + // UE_LOG(LogTemp, Error, TEXT("This is an Error")); + // UE_LOG(LogTemp, Display, TEXT("This is a Normal Message")); + + // FString Log = TEXT("Hello"); + // FString* LogPtr = &Log; + + // Log.Len(); + // (*LogPtr).Len(); // .Len wird zuerst ausgeführt, damit variable erreichbar () benutzen + // LogPtr->Len(); // -> zum aufruf von methoden von werten auf den pointer zeigen + + // UE_LOG(LogTemp, Warning, TEXT("%s"), *Log); + // UE_LOG(LogTemp, Warning, TEXT("%s"), **LogPtr); + + // FString OwnerName = GetOwner()->GetName(); + // UE_LOG(LogTemp, Warning, TEXT("%s"), *OwnerName); + // UE_LOG(LogTemp, Warning, TEXT("My name is: %s"), *GetOwner()->GetName()); \ No newline at end of file diff --git a/Source/BuildingEscape/WorldPosition.h b/Source/BuildingEscape/WorldPosition.h new file mode 100644 index 0000000..439b982 --- /dev/null +++ b/Source/BuildingEscape/WorldPosition.h @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "WorldPosition.generated.h" // muss unten sein + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class BUILDINGESCAPE_API UWorldPosition : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UWorldPosition(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + +}; diff --git a/Source/BuildingEscapeEditor.Target.cs b/Source/BuildingEscapeEditor.Target.cs new file mode 100644 index 0000000..d757b24 --- /dev/null +++ b/Source/BuildingEscapeEditor.Target.cs @@ -0,0 +1,14 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +using UnrealBuildTool; +using System.Collections.Generic; + +public class BuildingEscapeEditorTarget : TargetRules +{ + public BuildingEscapeEditorTarget(TargetInfo Target) : base(Target) + { + Type = TargetType.Editor; + + ExtraModuleNames.AddRange( new string[] { "BuildingEscape" } ); + } +}