Navigation Updates

This commit is contained in:
Vyktori 2025-04-23 12:06:59 -04:00
parent e79570aeae
commit 966c3ed39d
8 changed files with 54 additions and 32 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -4,7 +4,7 @@
#include "Gameplay/Robot/Components/Movement/LRMC_Stretch.h"
#include "Actors/MujocoVolumeActor.h"
#include "Gameplay/Robot/LuckyRobotPawnBase.h"
#include "Kismet/KismetMathLibrary.h"
//#include "Kismet/KismetMathLibrary.h"
void ULRMC_Stretch::PerformMovement(float DeltaTime, const ERobotInputHandlingMethod InputHandlingMethod, const ERobotInputType InputType, const FVector2D& InputValues)
@ -68,7 +68,8 @@ void ULRMC_Stretch::PerformMovement(float DeltaTime, const ERobotInputHandlingMe
case ERobotInputType::Turn:
{
PreviousInputType = ERobotInputType::Turn;
Turn(DeltaTime, InputValues.Y);
//Turn(DeltaTime, InputValues.Y);
Move(DeltaTime, InputValues);
}
break;
case ERobotInputType::Pathfinding:
@ -93,39 +94,18 @@ void ULRMC_Stretch::Move(const float DeltaTime, const FVector2D& InputValues) co
{
if (GetOwningRobot() && GetMujocoVolumeActor())
{
float Input_0 = InputValues.X;
float Input_1 = InputValues.X;
const FVector2D InterpolatedInputs = FMath::Vector2DInterpTo(PreviousSpeedValues, InputValues, DeltaTime, 3.f);
float Input_0 = InterpolatedInputs.X;
float Input_1 = InterpolatedInputs.X;
const float TargetSpeed = GetTargetSpeed();
const FVector Forward = GetRobotForwardVector();
const FVector DirectionToTarget = (PathfindingTargetLocation - GetRobotLocation()).GetSafeNormal();
const float DirectionDot = FVector::DotProduct(Forward, DirectionToTarget);
const float TurnMod = GetTurnModifier() * IsPathfinding() ? 2.f : 1.f;
const bool bRight = FVector::DotProduct(DirectionToTarget, GetRobotRightVector()) >= 0.f;
const float DirectionDelta = FMath::Abs<float>(1.f - DirectionDot);
const float DirectionOffset = FMath::Min<float>(DirectionDelta * TargetSpeed * 10.f, TargetSpeed) * 2.f;
UE_LOG(LogTemp, Warning, TEXT("RobotMove :: DirectionOffset (%f)"), DirectionOffset);
Input_0 -= InterpolatedInputs.Y * TargetSpeed * TurnMod;
Input_1 += InterpolatedInputs.Y * TargetSpeed * TurnMod;
if (!FMath::IsNearlyZero(DirectionOffset, 0.01f))
{
if (bRight)
{
Input_1 -= DirectionOffset;
}
else
{
Input_0 -= DirectionOffset;
}
}
const float TargetSpeedMod = GetTargetSpeedMod() * 0.5f;
Input_0 = FMath::Min<float>(Input_0, GetTargetSpeed()) * TargetSpeedMod;
Input_1 = FMath::Min<float>(Input_1, GetTargetSpeed()) * TargetSpeedMod;
UE_LOG(LogTemp, Warning, TEXT("RobotMove Inputs :: Left [%f] :: Right [%f]"), Input_0, Input_1);
Input_0 = FMath::Min<float>(Input_0, TargetSpeed) * 0.5f;
Input_1 = FMath::Min<float>(Input_1, TargetSpeed) * 0.5f;
GetMujocoVolumeActor()->SetActuatorValueByIndex(0, Input_0);
GetMujocoVolumeActor()->SetActuatorValueByIndex(1, Input_1);

View File

@ -32,6 +32,7 @@ void ULuckyRobotMovementComponent::TickComponent(float DeltaTime, enum ELevelTic
PerformMovement(DeltaTime, RobotSettings.InputHandlingMethod, GetOwningRobot()->GetCurrentInputType(), CurrentSpeedValues);
PreviousLocation = CurrentLocation;
PreviousSpeedValues = CurrentSpeedValues;
UE_LOG(LogTemp, Warning, TEXT("CurrentRobotSpeed (%f)"), CurrentRobotSpeed);
}
@ -187,6 +188,7 @@ void ULuckyRobotMovementComponent::HandlePathfindingInputs(const float DeltaTime
if (FVector::Distance(CurrentTransform.GetLocation(), PathfindingDestination) <= PathfindingDestinationTolerance)
{
GetOwningRobot()->PathfindingComplete(true);
GetOwningRobot()->SetPathfindingInputValues();
return;
}
@ -248,7 +250,8 @@ FVector ULuckyRobotMovementComponent::GetSplineTargetLocation(const float Curren
{
if (GetNavPath().GetSplinePath())
{
const float ForwardPathCheck = FMath::Clamp<float>(GetTargetSpeed() * 0.5f, 20.f, 50.f);
constexpr float ForwardOffset = 10.f;
const float ForwardPathCheck = FMath::Clamp<float>(GetTargetSpeed(), 15.f, 50.f) + ForwardOffset;
const float SplineCheckDistance = CurrentDistance + ForwardPathCheck;
if (SplineCheckDistance >= GetNavPath().GetSplinePath()->GetSplineLength())
{
@ -318,3 +321,13 @@ float ULuckyRobotMovementComponent::GetTargetSpeedMod() const
{
return UKismetMathLibrary::SafeDivide(GetTargetSpeed(), CurrentRobotSpeed);
}
float ULuckyRobotMovementComponent::GetTurnModifier() const
{
if (GetOwningRobot())
{
return GetOwningRobot()->GetTurnModifier();
}
return 1.f;
}

View File

@ -2,6 +2,8 @@
#include "Subsystems/LuckyWorldSubsystem.h"
#include "NavigationPath.h"
#include "Gameplay/Robot/LuckyRobotPawnBase.h"
void ULuckyWorldSubsystem::CheckSimulationReady()
@ -83,3 +85,20 @@ void ULuckyWorldSubsystem::UpdateRobotNavPath(const FRobotNavPath& InRobotNavPat
RobotNavPathChanged.Broadcast(RobotNavPath);
}
}
FRobotNavPath ULuckyWorldSubsystem::GenerateRobotNavPath_Navigation(UNavigationPath* InNavPath)
{
FRobotNavPath NewNavPath = FRobotNavPath();
if (IsValid(InNavPath))
{
for (auto const& Point : InNavPath->PathPoints)
{
FRobotNavPoint NewPoint = FRobotNavPoint();
NewPoint.Location = Point;
NewNavPath.NavPoints.Add(NewPoint);
}
}
return NewNavPath;
}

View File

@ -54,6 +54,7 @@ public:
virtual void StopMovement();
float GetTargetSpeed() const;
float GetTargetSpeedMod() const;
float GetTurnModifier() const;
protected:
virtual void BeginPlay() override;
@ -68,6 +69,7 @@ protected:
virtual void InterpolateSpeedValues(const float DeltaTime, const float Acceleration, const float Deceleration);
FVector2D CurrentSpeedValues = FVector2D::ZeroVector;
FVector2D PreviousSpeedValues = FVector2D::ZeroVector;
float PathfindingTargetSpeed = 0.f;
float PathfindingDestinationTolerance = 10.f;
FVector PathfindingTargetLocation = FVector::ZeroVector;

View File

@ -8,6 +8,7 @@
#include "LuckyWorldSubsystem.generated.h"
class UNavigationPath;
class AMujocoVolumeActor;
class ALuckyRobotPawnBase;
@ -77,6 +78,9 @@ public:
UPROPERTY(BlueprintAssignable, Category = "Lucky World Subsystem")
FLuckyRobotNavPathChangedDelegate RobotNavPathChanged;
UFUNCTION(BlueprintCallable, Category = "Lucky World Subsystem")
FRobotNavPath GenerateRobotNavPath_Navigation(UNavigationPath* InNavPath);
protected:
TWeakObjectPtr<ALuckyRobotPawnBase> LuckyRobotPawn;