Navigation Updates
This commit is contained in:
parent
e79570aeae
commit
966c3ed39d
File diff suppressed because one or more lines are too long
Binary file not shown.
BIN
Content/Map/EmptyTestLevel.umap
Normal file
BIN
Content/Map/EmptyTestLevel.umap
Normal file
Binary file not shown.
@ -4,7 +4,7 @@
|
|||||||
#include "Gameplay/Robot/Components/Movement/LRMC_Stretch.h"
|
#include "Gameplay/Robot/Components/Movement/LRMC_Stretch.h"
|
||||||
#include "Actors/MujocoVolumeActor.h"
|
#include "Actors/MujocoVolumeActor.h"
|
||||||
#include "Gameplay/Robot/LuckyRobotPawnBase.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)
|
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:
|
case ERobotInputType::Turn:
|
||||||
{
|
{
|
||||||
PreviousInputType = ERobotInputType::Turn;
|
PreviousInputType = ERobotInputType::Turn;
|
||||||
Turn(DeltaTime, InputValues.Y);
|
//Turn(DeltaTime, InputValues.Y);
|
||||||
|
Move(DeltaTime, InputValues);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ERobotInputType::Pathfinding:
|
case ERobotInputType::Pathfinding:
|
||||||
@ -93,39 +94,18 @@ void ULRMC_Stretch::Move(const float DeltaTime, const FVector2D& InputValues) co
|
|||||||
{
|
{
|
||||||
if (GetOwningRobot() && GetMujocoVolumeActor())
|
if (GetOwningRobot() && GetMujocoVolumeActor())
|
||||||
{
|
{
|
||||||
float Input_0 = InputValues.X;
|
const FVector2D InterpolatedInputs = FMath::Vector2DInterpTo(PreviousSpeedValues, InputValues, DeltaTime, 3.f);
|
||||||
float Input_1 = InputValues.X;
|
float Input_0 = InterpolatedInputs.X;
|
||||||
|
float Input_1 = InterpolatedInputs.X;
|
||||||
|
|
||||||
const float TargetSpeed = GetTargetSpeed();
|
const float TargetSpeed = GetTargetSpeed();
|
||||||
|
const float TurnMod = GetTurnModifier() * IsPathfinding() ? 2.f : 1.f;
|
||||||
const FVector Forward = GetRobotForwardVector();
|
|
||||||
const FVector DirectionToTarget = (PathfindingTargetLocation - GetRobotLocation()).GetSafeNormal();
|
|
||||||
const float DirectionDot = FVector::DotProduct(Forward, DirectionToTarget);
|
|
||||||
|
|
||||||
const bool bRight = FVector::DotProduct(DirectionToTarget, GetRobotRightVector()) >= 0.f;
|
Input_0 -= InterpolatedInputs.Y * TargetSpeed * TurnMod;
|
||||||
const float DirectionDelta = FMath::Abs<float>(1.f - DirectionDot);
|
Input_1 += InterpolatedInputs.Y * TargetSpeed * TurnMod;
|
||||||
const float DirectionOffset = FMath::Min<float>(DirectionDelta * TargetSpeed * 10.f, TargetSpeed) * 2.f;
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("RobotMove :: DirectionOffset (%f)"), DirectionOffset);
|
|
||||||
|
|
||||||
|
Input_0 = FMath::Min<float>(Input_0, TargetSpeed) * 0.5f;
|
||||||
if (!FMath::IsNearlyZero(DirectionOffset, 0.01f))
|
Input_1 = FMath::Min<float>(Input_1, TargetSpeed) * 0.5f;
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
GetMujocoVolumeActor()->SetActuatorValueByIndex(0, Input_0);
|
GetMujocoVolumeActor()->SetActuatorValueByIndex(0, Input_0);
|
||||||
GetMujocoVolumeActor()->SetActuatorValueByIndex(1, Input_1);
|
GetMujocoVolumeActor()->SetActuatorValueByIndex(1, Input_1);
|
||||||
|
@ -32,6 +32,7 @@ void ULuckyRobotMovementComponent::TickComponent(float DeltaTime, enum ELevelTic
|
|||||||
PerformMovement(DeltaTime, RobotSettings.InputHandlingMethod, GetOwningRobot()->GetCurrentInputType(), CurrentSpeedValues);
|
PerformMovement(DeltaTime, RobotSettings.InputHandlingMethod, GetOwningRobot()->GetCurrentInputType(), CurrentSpeedValues);
|
||||||
|
|
||||||
PreviousLocation = CurrentLocation;
|
PreviousLocation = CurrentLocation;
|
||||||
|
PreviousSpeedValues = CurrentSpeedValues;
|
||||||
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("CurrentRobotSpeed (%f)"), CurrentRobotSpeed);
|
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)
|
if (FVector::Distance(CurrentTransform.GetLocation(), PathfindingDestination) <= PathfindingDestinationTolerance)
|
||||||
{
|
{
|
||||||
GetOwningRobot()->PathfindingComplete(true);
|
GetOwningRobot()->PathfindingComplete(true);
|
||||||
|
GetOwningRobot()->SetPathfindingInputValues();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +250,8 @@ FVector ULuckyRobotMovementComponent::GetSplineTargetLocation(const float Curren
|
|||||||
{
|
{
|
||||||
if (GetNavPath().GetSplinePath())
|
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;
|
const float SplineCheckDistance = CurrentDistance + ForwardPathCheck;
|
||||||
if (SplineCheckDistance >= GetNavPath().GetSplinePath()->GetSplineLength())
|
if (SplineCheckDistance >= GetNavPath().GetSplinePath()->GetSplineLength())
|
||||||
{
|
{
|
||||||
@ -318,3 +321,13 @@ float ULuckyRobotMovementComponent::GetTargetSpeedMod() const
|
|||||||
{
|
{
|
||||||
return UKismetMathLibrary::SafeDivide(GetTargetSpeed(), CurrentRobotSpeed);
|
return UKismetMathLibrary::SafeDivide(GetTargetSpeed(), CurrentRobotSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ULuckyRobotMovementComponent::GetTurnModifier() const
|
||||||
|
{
|
||||||
|
if (GetOwningRobot())
|
||||||
|
{
|
||||||
|
return GetOwningRobot()->GetTurnModifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1.f;
|
||||||
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Subsystems/LuckyWorldSubsystem.h"
|
#include "Subsystems/LuckyWorldSubsystem.h"
|
||||||
|
|
||||||
|
#include "NavigationPath.h"
|
||||||
#include "Gameplay/Robot/LuckyRobotPawnBase.h"
|
#include "Gameplay/Robot/LuckyRobotPawnBase.h"
|
||||||
|
|
||||||
void ULuckyWorldSubsystem::CheckSimulationReady()
|
void ULuckyWorldSubsystem::CheckSimulationReady()
|
||||||
@ -83,3 +85,20 @@ void ULuckyWorldSubsystem::UpdateRobotNavPath(const FRobotNavPath& InRobotNavPat
|
|||||||
RobotNavPathChanged.Broadcast(RobotNavPath);
|
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;
|
||||||
|
}
|
||||||
|
@ -54,6 +54,7 @@ public:
|
|||||||
virtual void StopMovement();
|
virtual void StopMovement();
|
||||||
float GetTargetSpeed() const;
|
float GetTargetSpeed() const;
|
||||||
float GetTargetSpeedMod() const;
|
float GetTargetSpeedMod() const;
|
||||||
|
float GetTurnModifier() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
@ -68,6 +69,7 @@ protected:
|
|||||||
virtual void InterpolateSpeedValues(const float DeltaTime, const float Acceleration, const float Deceleration);
|
virtual void InterpolateSpeedValues(const float DeltaTime, const float Acceleration, const float Deceleration);
|
||||||
|
|
||||||
FVector2D CurrentSpeedValues = FVector2D::ZeroVector;
|
FVector2D CurrentSpeedValues = FVector2D::ZeroVector;
|
||||||
|
FVector2D PreviousSpeedValues = FVector2D::ZeroVector;
|
||||||
float PathfindingTargetSpeed = 0.f;
|
float PathfindingTargetSpeed = 0.f;
|
||||||
float PathfindingDestinationTolerance = 10.f;
|
float PathfindingDestinationTolerance = 10.f;
|
||||||
FVector PathfindingTargetLocation = FVector::ZeroVector;
|
FVector PathfindingTargetLocation = FVector::ZeroVector;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "LuckyWorldSubsystem.generated.h"
|
#include "LuckyWorldSubsystem.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
class UNavigationPath;
|
||||||
class AMujocoVolumeActor;
|
class AMujocoVolumeActor;
|
||||||
class ALuckyRobotPawnBase;
|
class ALuckyRobotPawnBase;
|
||||||
|
|
||||||
@ -77,6 +78,9 @@ public:
|
|||||||
|
|
||||||
UPROPERTY(BlueprintAssignable, Category = "Lucky World Subsystem")
|
UPROPERTY(BlueprintAssignable, Category = "Lucky World Subsystem")
|
||||||
FLuckyRobotNavPathChangedDelegate RobotNavPathChanged;
|
FLuckyRobotNavPathChangedDelegate RobotNavPathChanged;
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Lucky World Subsystem")
|
||||||
|
FRobotNavPath GenerateRobotNavPath_Navigation(UNavigationPath* InNavPath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TWeakObjectPtr<ALuckyRobotPawnBase> LuckyRobotPawn;
|
TWeakObjectPtr<ALuckyRobotPawnBase> LuckyRobotPawn;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user