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