Clamp character and camera position to stage boundaries
Clamp character and camera position to stage boundaries
This commit is contained in:
parent
0942a3a1c6
commit
6d3b189234
BIN
KOFForever/Content/Maps/DebugStage.umap
(Stored with Git LFS)
BIN
KOFForever/Content/Maps/DebugStage.umap
(Stored with Git LFS)
Binary file not shown.
@ -7,6 +7,7 @@
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Character/KOFBaseCharacter.h"
|
||||
#include "GameModes/KOFDefaultGameMode.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
AKOFDefaultCamera::AKOFDefaultCamera()
|
||||
{
|
||||
@ -42,7 +43,8 @@ void AKOFDefaultCamera::Tick(float DeltaSeconds)
|
||||
FVector P2Loc = P2->GetActorLocation();
|
||||
FVector CameraLoc = GetActorLocation();
|
||||
|
||||
FVector MidPoint = FVector(CameraLoc.X, (P1Loc.Y + P2Loc.Y) / 2.0f, ((P1Loc.Z + P2Loc.Z) / ZAveragingFactor) + HeightOffset);
|
||||
float HalfStageLength = GameMode->GetStageLength() / 2.0f;
|
||||
FVector MidPoint = FVector(CameraLoc.X, FMath::Clamp((P1Loc.Y + P2Loc.Y) / 2.0f, -HalfStageLength, HalfStageLength), ((P1Loc.Z + P2Loc.Z) / ZAveragingFactor) + HeightOffset);
|
||||
SetActorLocation(MidPoint);
|
||||
|
||||
// set FOV
|
||||
|
@ -40,37 +40,11 @@ void UKOFCharacterMovementComponent::TickComponent(float DeltaTime, ELevelTick T
|
||||
FVector CurrentLoc = Owner->GetActorLocation();
|
||||
Owner->SetActorLocation(FVector(CurrentLoc.X, AdjustedY, CurrentLoc.Z));
|
||||
}
|
||||
}
|
||||
|
||||
void UKOFCharacterMovementComponent::PostPhysicsTickComponent(float DeltaTime,
|
||||
FCharacterMovementComponentPostPhysicsTickFunction& ThisTickFunction)
|
||||
{
|
||||
Super::PostPhysicsTickComponent(DeltaTime, ThisTickFunction);
|
||||
|
||||
AKOFBaseCharacter* Owner = Cast<AKOFBaseCharacter>(GetOwner());
|
||||
if(!Owner)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("AKOFCharacterMovementComponent::PostPhysicsTickComponent - could not get the owner"));
|
||||
return;
|
||||
}
|
||||
|
||||
AKOFDefaultGameMode* GameMode = Cast<AKOFDefaultGameMode>(GetWorld()->GetAuthGameMode());
|
||||
if(!GameMode)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("AKOFCharacterMovementComponent::PostPhysicsTickComponent - could not get the game mode"));
|
||||
return;
|
||||
}
|
||||
|
||||
AKOFBaseCharacter* Opponent = GameMode->GetCurrentOpponent(Owner->IsPossessedByPlayer1());
|
||||
if(Opponent)
|
||||
{
|
||||
float YDistance = FMath::Abs(Opponent->GetActorLocation().Y - Owner->GetActorLocation().Y);
|
||||
float HalfYDistance = YDistance / 2.0f;
|
||||
float YMidpoint = (Owner->GetActorLocation().Y + Opponent->GetActorLocation().Y) / 2.0f;
|
||||
|
||||
float AdjustedY = FMath::Clamp(Owner->GetActorLocation().Y, YMidpoint - HalfYDistance, YMidpoint + HalfYDistance);
|
||||
|
||||
// clamp to stage bounds
|
||||
FVector CurrentLoc = Owner->GetActorLocation();
|
||||
Owner->SetActorLocation(FVector(CurrentLoc.X, AdjustedY, CurrentLoc.Z));
|
||||
}
|
||||
float HalfStageLength = GameMode->GetStageLength() / 2.0f;
|
||||
Owner->SetActorLocation(FVector(CurrentLoc.X,
|
||||
FMath::Clamp(CurrentLoc.Y, -HalfStageLength, HalfStageLength),
|
||||
CurrentLoc.Z));
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ AKOFDefaultGameMode::AKOFDefaultGameMode()
|
||||
NumCharactersPerTeam = 3;
|
||||
|
||||
MaxAllowedDistanceFromOpponent = 700.0f;
|
||||
StageLength = 2400.0f;
|
||||
StartY = 250.0f;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,4 @@ class KOFFOREVER_API UKOFCharacterMovementComponent : public UCharacterMovementC
|
||||
UKOFCharacterMovementComponent();
|
||||
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
virtual void PostPhysicsTickComponent(float DeltaTime, FCharacterMovementComponentPostPhysicsTickFunction& ThisTickFunction) override;
|
||||
};
|
||||
|
@ -33,6 +33,8 @@ public:
|
||||
|
||||
FORCEINLINE float GetMaxAllowedDistanceFromOpponent() { return MaxAllowedDistanceFromOpponent; }
|
||||
|
||||
FORCEINLINE float GetStageLength() { return StageLength; }
|
||||
|
||||
protected:
|
||||
/** Number of characters on a single player's team */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Settings|Team")
|
||||
@ -42,6 +44,9 @@ protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Settings|Stage")
|
||||
float MaxAllowedDistanceFromOpponent;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Settings|Stage")
|
||||
float StageLength;
|
||||
|
||||
/** Y offset from origin where character's will be spawned */
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Settings|Stage")
|
||||
float StartY;
|
||||
|
Loading…
Reference in New Issue
Block a user