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>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="8acc2658-cb31-4c49-857f-282cfee74640" name="Changes" comment=""> <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$/.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/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/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/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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -26,37 +29,37 @@
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
<component name="ProjectColorInfo"><![CDATA[{ <component name="ProjectColorInfo">{
"customColor": "", &quot;customColor&quot;: &quot;&quot;,
"associatedIndex": 5 &quot;associatedIndex&quot;: 5
}]]></component> }</component>
<component name="ProjectId" id="2bBQ5ZFjKADdlvCf2VePqJdIy1m" /> <component name="ProjectId" id="2bBQ5ZFjKADdlvCf2VePqJdIy1m" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"C++ Project.EndlessVendetta.executor": "Run", &quot;C++ Project.EndlessVendetta.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "dev", &quot;git-widget-placeholder&quot;: &quot;HomeHub-Tutorial&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}, },
"keyToStringList": { &quot;keyToStringList&quot;: {
"rider.external.source.directories": [ &quot;rider.external.source.directories&quot;: [
"C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache", &quot;C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\DecompilerCache&quot;,
"C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache", &quot;C:\\Users\\Rafal\\AppData\\Roaming\\JetBrains\\Rider2023.3\\resharper-host\\SourcesCache&quot;,
"C:\\Users\\Rafal\\AppData\\Local\\Symbols\\src" &quot;C:\\Users\\Rafal\\AppData\\Local\\Symbols\\src&quot;
] ]
} }
}]]></component> }</component>
<component name="RunManager"> <component name="RunManager">
<configuration name="EndlessVendetta" type="CppProject" factoryName="C++ Project"> <configuration name="EndlessVendetta" type="CppProject" factoryName="C++ Project">
<configuration_1> <configuration_1>
@ -128,7 +131,8 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1705685810960</updated> <updated>1705685810960</updated>
<workItem from="1705685813496" duration="640000" /> <workItem from="1705685813496" duration="6457000" />
<workItem from="1705756768038" duration="3221000" />
</task> </task>
<servers /> <servers />
</component> </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) void ALandingZone::UpdateAllLandingZones(bool Landing)
{ {
TArray<AActor*> AllLandingZones; TArray<AActor*> AllLandingZones;
@ -22,6 +60,7 @@ void ALandingZone::UpdateAllLandingZones(bool Landing)
{ {
ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor); ALandingZone* LZ = Cast<ALandingZone>(LZ_Actor);
Landing ? LZ->HideWaypoint() : LZ->ShowWaypoint(); Landing ? LZ->HideWaypoint() : LZ->ShowWaypoint();
LZ->IsWaypointVisible = !Landing;
} }
} }

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Components/WidgetComponent.h"
#include "EndlessVendetta/InteractionInterface.h" #include "EndlessVendetta/InteractionInterface.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "LandingZone.generated.h" #include "LandingZone.generated.h"
@ -12,22 +13,42 @@ class ENDLESSVENDETTA_API ALandingZone : public AActor, public IInteractionInter
{ {
GENERATED_BODY() GENERATED_BODY()
// ------------------------------ Attributes -------------------------------------------------
UPROPERTY(EditAnywhere, Category = "Landing Zone") UPROPERTY(EditAnywhere, Category = "Landing Zone")
FTransform LZ_ExitTransform; FTransform LZ_ExitTransform;
UPROPERTY(EditAnywhere, Category = "Landing Zone") UPROPERTY(EditAnywhere, Category = "Landing Zone")
FTransform LZ_TakeoffTransform; FTransform LZ_TakeoffTransform;
// Hides or shows key aesthetic features of LZ's based on if the player is landing or not UWidgetComponent* WaypointWidgetComponent;
void UpdateAllLandingZones(bool Landing);
APawn* PlayersPawn;
protected: protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Landing Zone") UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Landing Zone")
bool IsHomeBase_LZ = false; 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 // Allows player to enter their ship through a LZ
void Interact() override; void Interact() override;
// Used to implement a pop up for interaction
void InteractPrompt() override; void InteractPrompt() override;
public: public:
@ -41,12 +62,14 @@ public:
// Ran when a player takes off from any LZ in the world // Ran when a player takes off from any LZ in the world
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void ShowWaypoint(); void ShowWaypoint();
// Ran when player lands at any LZ in the world // Ran when player lands at any LZ in the world
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void HideWaypoint(); void HideWaypoint();
// Updates all LZ's, then runs exit ship func on player and passes the exit transform // Updates all LZ's, then runs exit ship func on player and passes the exit transform
void Land(); void Land();
// Updates all LZ's, then runs enter ship func on player passing the correct takeoff transform // Updates all LZ's, then runs enter ship func on player passing the correct takeoff transform
void Takeoff(); void Takeoff();
}; };