Optimised LandingZone Waypoint Transform Update from BP to C++

This commit is contained in:
Rafal Swierczek 2024-01-20 14:23:05 +00:00
parent 542b09012b
commit b167dcca01
6 changed files with 102 additions and 36 deletions

View File

@ -8,12 +8,15 @@
</component>
<component name="ChangeListManager">
<list default="true" id="8acc2658-cb31-4c49-857f-282cfee74640" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.EndlessVendetta/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.EndlessVendetta/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.EndlessVendetta/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.EndlessVendetta/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset" beforeDir="false" afterPath="$PROJECT_DIR$/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Content/Levels/ControlTutorialLevel.umap" beforeDir="false" afterPath="$PROJECT_DIR$/Content/Levels/ControlTutorialLevel.umap" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Content/Ships/LandingZone.uasset" beforeDir="false" afterPath="$PROJECT_DIR$/Content/Ships/LandingZone.uasset" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset" beforeDir="false" afterPath="$PROJECT_DIR$/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Content/StarterContent/Particles/P_Ambient_Dust.uasset" beforeDir="false" afterPath="$PROJECT_DIR$/Content/StarterContent/Particles/P_Ambient_Dust.uasset" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Source/EndlessVendetta/EndlessVendettaCharacter.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Source/EndlessVendetta/EndlessVendettaCharacter.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Source/EndlessVendetta/EndlessVendettaCharacter.h" beforeDir="false" afterPath="$PROJECT_DIR$/Source/EndlessVendetta/EndlessVendettaCharacter.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Source/EndlessVendetta/SpaceShip/LandingZone.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Source/EndlessVendetta/SpaceShip/LandingZone.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Source/EndlessVendetta/SpaceShip/LandingZone.h" beforeDir="false" afterPath="$PROJECT_DIR$/Source/EndlessVendetta/SpaceShip/LandingZone.h" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -26,37 +29,37 @@
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"customColor": "",
"associatedIndex": 5
}]]></component>
<component name="ProjectColorInfo">{
&quot;customColor&quot;: &quot;&quot;,
&quot;associatedIndex&quot;: 5
}</component>
<component name="ProjectId" id="2bBQ5ZFjKADdlvCf2VePqJdIy1m" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"C++ Project.EndlessVendetta.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "dev",
"ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;C++ Project.EndlessVendetta.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;HomeHub-Tutorial&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
},
"keyToStringList": {
"rider.external.source.directories": [
"C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache",
"C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache",
"C:\\Users\\Rafal\\AppData\\Local\\Symbols\\src"
&quot;keyToStringList&quot;: {
&quot;rider.external.source.directories&quot;: [
&quot;C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache&quot;,
&quot;C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache&quot;,
&quot;C:\\Users\\Rafal\\AppData\\Local\\Symbols\\src&quot;
]
}
}]]></component>
}</component>
<component name="RunManager">
<configuration name="EndlessVendetta" type="CppProject" factoryName="C++ Project">
<configuration_1>
@ -128,7 +131,8 @@
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1705685810960</updated>
<workItem from="1705685813496" duration="640000" />
<workItem from="1705685813496" duration="6457000" />
<workItem from="1705756768038" duration="3221000" />
</task>
<servers />
</component>

Binary file not shown.

Binary file not shown.

View File

@ -14,6 +14,44 @@ ALandingZone::ALandingZone()
}
void ALandingZone::BeginPlay()
{
WaypointWidgetComponent = Cast<UWidgetComponent>(GetComponentByClass(UWidgetComponent::StaticClass()));
PlayersPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
// Tick updates the waypoints transform base on players location
if (!IsValid(WaypointWidgetComponent) || !IsValid(PlayersPawn)) SetActorTickEnabled(false);
Super::BeginPlay();
}
void ALandingZone::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (!IsWaypointVisible) return;
UpdateWaypointTransform();
}
void ALandingZone::UpdateWaypointTransform()
{
FVector WaypointLoc = WaypointWidgetComponent->GetComponentLocation();
FVector PlayerLoc = PlayersPawn->GetActorLocation();
// Update rotation
FVector LocationDiffVector = PlayerLoc - WaypointLoc;
FRotator LookAtPlayerRotator = LocationDiffVector.Rotation();
WaypointWidgetComponent->SetWorldRotation(LookAtPlayerRotator);
// Update scale
double DistanceFromPlayer = LocationDiffVector.Length();
double ScaleMagnitude = (12.f - 0.15f) / (48000.f - 900.f);
double ScaleIntercept = 12.f - (48000.f * ScaleMagnitude);
double ResultingScale = (DistanceFromPlayer * ScaleMagnitude) + ScaleIntercept;
FVector WaypointScale = FVector(1, ResultingScale, ResultingScale);
WaypointWidgetComponent->SetWorldScale3D(WaypointScale);
}
void ALandingZone::UpdateAllLandingZones(bool Landing)
{
TArray<AActor*> AllLandingZones;
@ -22,6 +60,7 @@ void ALandingZone::UpdateAllLandingZones(bool Landing)
{
ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor);
Landing ? LZ->HideWaypoint() : LZ->ShowWaypoint();
LZ->IsWaypointVisible = !Landing;
}
}

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "Components/WidgetComponent.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "GameFramework/Actor.h"
#include "LandingZone.generated.h"
@ -11,29 +12,49 @@ UCLASS()
class ENDLESSVENDETTA_API ALandingZone : public AActor, public IInteractionInterface
{
GENERATED_BODY()
// ------------------------------ Attributes -------------------------------------------------
UPROPERTY(EditAnywhere, Category = "Landing Zone")
FTransform LZ_ExitTransform;
UPROPERTY(EditAnywhere, Category = "Landing Zone")
FTransform LZ_TakeoffTransform;
// Hides or shows key aesthetic features of LZ's based on if the player is landing or not
void UpdateAllLandingZones(bool Landing);
UWidgetComponent* WaypointWidgetComponent;
APawn* PlayersPawn;
protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Landing Zone")
bool IsHomeBase_LZ = false;
public:
bool IsWaypointVisible = false;
// ------------------------------ Methods -------------------------------------------------
private:
// Runs when game starts or this actor spawns
virtual void BeginPlay() override;
// Runs once per frame
virtual void Tick(float DeltaSeconds) override;
// Hides or shows key aesthetic features of LZ's based on if the player is landing or not
void UpdateAllLandingZones(bool Landing);
// Updates waypoints rotation and scale based on players location, only if visible
void UpdateWaypointTransform();
protected:
// Allows player to enter their ship through a LZ
void Interact() override;
// Used to implement a pop up for interaction
void InteractPrompt() override;
public:
// Sets default values for this actor's properties
ALandingZone();
// Waypoint will display something along the lines of Press F to Land
UFUNCTION(BlueprintImplementableEvent)
void SuggestLandingWidget();
@ -41,12 +62,14 @@ public:
// Ran when a player takes off from any LZ in the world
UFUNCTION(BlueprintImplementableEvent)
void ShowWaypoint();
// Ran when player lands at any LZ in the world
UFUNCTION(BlueprintImplementableEvent)
void HideWaypoint();
// Updates all LZ's, then runs exit ship func on player and passes the exit transform
void Land();
// Updates all LZ's, then runs enter ship func on player passing the correct takeoff transform
void Takeoff();
};