Hi.
I am trying to implement a restriction on movement by a player in a certain radius. How to prevent the player to go beyond the radius of the object? At the same time without restricting its movement within the region.
if (isLocomotingRight) {
// Player current position
FVector CurrentPosition(this->RootComponent->GetComponentLocation());
// The coordinates of the object around which we will walk
FVector AnchorPosition(2091.0f, -11052.0f, 0.0f);
// Calculate the distance to the object
FVector vector = AnchorPosition - CurrentPosition;
float AnchorDistance = vector.Size();
// Radius of limitation
float maxDistance = 220.0f;
/*Here I need some code to impose a value on offsetDir*/
// Next comes the calculation of the displacement
FVector offsetDir;
offsetDir = locomotionDirectionRightX * locomotionRightXMultiplier + locomotionDirectionRightY * locomotionRightYMultiplier;
offsetDir.Z = 0;
if (isLocomotionSpeedConstant) offsetDir.Normalize();
AddMovementInput(offsetDir);
}
Is there an elegant way to do this?