diagonal edge scroll improvements
This commit is contained in:
parent
7f4fd950df
commit
832507177f
@ -19,8 +19,8 @@ AAdventureCameraPawn::AAdventureCameraPawn()
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
ESASize = .01;
|
||||
BaseScrollSpeed = 15;
|
||||
ScrollAccelleration = BaseScrollSpeed * 2;
|
||||
BaseScrollSpeed = 16;
|
||||
ScrollAccelleration = BaseScrollSpeed * 2.2;
|
||||
|
||||
ESAMaxBoundSlope = 1 / (1 - (1-ESASize));
|
||||
ESAMaxBoundIntercept = 1 - ESAMaxBoundSlope;
|
||||
@ -36,9 +36,16 @@ void AAdventureCameraPawn::BeginPlay()
|
||||
Super::BeginPlay();
|
||||
ControllerRef = (AAdventurePlayerController*)UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
|
||||
// The Viewport properties are inaccurate right after BeginPlay, so we need to wait a short time before saving them here.
|
||||
FTimerHandle UnusedHandle;
|
||||
GetWorldTimerManager().SetTimer(
|
||||
UnusedHandle, this, &AAdventureCameraPawn::GetTheDamnViewport, 1.5, false);
|
||||
}
|
||||
|
||||
void AAdventureCameraPawn::GetTheDamnViewport()
|
||||
{
|
||||
Viewport = GetWorld()->GetGameViewport();
|
||||
ViewSize = Viewport->Viewport->GetSizeXY();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
@ -66,13 +73,19 @@ void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
|
||||
float mouseY;
|
||||
ControllerRef->GetMousePosition(mouseX, mouseY);
|
||||
float mousePosX = mouseX / ViewSize.X;
|
||||
float mousePosY = mouseY / ViewSize.Y;
|
||||
float VertAccelleration = GetInputAxisValue("Mouse Y") * (ScrollAccelleration * .75);
|
||||
|
||||
if (mousePosX <= ESASize) // if in LEFT area
|
||||
{
|
||||
////// Scroll LEFT with Vert Accelleration
|
||||
float SpeedX = (mousePosX * ESAMinBoundSlope + ESAMinBoundIntercept) * BaseScrollSpeed;
|
||||
AddActorLocalOffset(FVector(VertAccelleration, -SpeedX, 0));
|
||||
AddActorLocalOffset(FVector(0, -SpeedX, 0));
|
||||
|
||||
if (mousePosY > .005) // if not touching EDGE
|
||||
{
|
||||
AddActorLocalOffset(FVector(VertAccelleration, 0, 0));
|
||||
}
|
||||
|
||||
if (AxisValue < .0 && mousePosX <= .005) // if mouse moving LEFT and touching EDGE
|
||||
{
|
||||
@ -84,9 +97,14 @@ void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
|
||||
|
||||
if (mousePosX >= 1-ESASize) // if in RIGHT area
|
||||
{
|
||||
////// Scroll RIGHT
|
||||
////// Scroll RIGHT with Vert Accelleration
|
||||
float SpeedX = (mousePosX * ESAMaxBoundSlope + ESAMaxBoundIntercept) * BaseScrollSpeed;
|
||||
AddActorLocalOffset(FVector(VertAccelleration, SpeedX, 0));
|
||||
AddActorLocalOffset(FVector(0, SpeedX, 0));
|
||||
|
||||
if (mousePosY < .995) // if not touching EDGE
|
||||
{
|
||||
AddActorLocalOffset(FVector(VertAccelleration, 0, 0));
|
||||
}
|
||||
|
||||
if (AxisValue > .0 && mousePosX >= .995) // if mouse moving RIGHT and touching EDGE
|
||||
{
|
||||
@ -103,14 +121,20 @@ void AAdventureCameraPawn::EdgeScrollVert(float AxisValue)
|
||||
float mouseY;
|
||||
ControllerRef->GetMousePosition(mouseX, mouseY);
|
||||
float mousePosY = mouseY / ViewSize.Y;
|
||||
float mousePosX = mouseX / ViewSize.X;
|
||||
float SideAccelleration = GetInputAxisValue("Mouse X") * (ScrollAccelleration * .75);
|
||||
|
||||
if (mousePosY <= ESASize) // if in TOP area
|
||||
{
|
||||
////// Scroll TOP
|
||||
////// Scroll TOP with Side Accelleration
|
||||
float SpeedY = (mousePosY * ESAMinBoundSlope + ESAMinBoundIntercept) * BaseScrollSpeed;
|
||||
AddActorLocalOffset(FVector(SpeedY, SideAccelleration, 0));
|
||||
|
||||
if (mousePosX > .005) // if not touching EDGE
|
||||
{
|
||||
AddActorLocalOffset(FVector(0, SideAccelleration, 0));
|
||||
}
|
||||
|
||||
if (AxisValue > .0 && mousePosY <= .005) // if mouse moving TOP and touching EDGE
|
||||
{
|
||||
////// Add TOP accelleration
|
||||
@ -121,10 +145,15 @@ void AAdventureCameraPawn::EdgeScrollVert(float AxisValue)
|
||||
|
||||
if (mousePosY >= 1-ESASize) // if in BOTTOM area
|
||||
{
|
||||
////// Scroll BOTTOM
|
||||
////// Scroll BOTTOM with Side Accelleration
|
||||
float SpeedY = (mousePosY * ESAMaxBoundSlope + ESAMaxBoundIntercept) * BaseScrollSpeed;
|
||||
AddActorLocalOffset(FVector(-SpeedY, SideAccelleration, 0));
|
||||
|
||||
if (mousePosX < .995) // if not touching EDGE
|
||||
{
|
||||
AddActorLocalOffset(FVector(0, SideAccelleration, 0));
|
||||
}
|
||||
|
||||
if (AxisValue < .0 && mousePosY >= .995) // if mouse moving BOTTOM and touching EDGE
|
||||
{
|
||||
////// add BOTTOM accelleration
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
void GetTheDamnViewport();
|
||||
|
||||
float ESAMaxBoundSlope;
|
||||
float ESAMaxBoundIntercept;
|
||||
|
Loading…
Reference in New Issue
Block a user