Thank you for the reply. That code is doing the same as the above was.
So in the Pawn input function, MoveCamera I pass the MovementVector to the TraceFromCamera function (So TraceFromCamera only fires when a key is pressed).
// Get Axis value.
const FVector MovementVector = Value.Get<FVector>();
if (MovementVector.X != 0 || MovementVector.Y != 0)
{
TraceFromCamera(MovementVector);
}
Which is giving me the Axis value. (Right (D) X: 1.0, Up (W) Y: 1.0) etc.
In my TraceFromCamera function I have tried to adapt your code above to:
UWorld* World = GetWorld();
if (World != nullptr)
{
FVector2D ViewportPosition;
FVector2D ViewportSize;
World->GetGameViewport()->GetViewportSize(ViewportSize);
// Check if vertical movement.
if (MovementVector.Y > 0)
{
ViewportPosition = FVector2D(ViewportSize.X * 0.5, ViewportSize.Y); // Removed * (float)!bIsPositive) as it would of been 0?
}
else
{
ViewportPosition = FVector2D(1.0f * ViewportSize.X, ViewportSize.Y * 0.5); // Added * 1.0f, as bIsPositive would be 1.0?
}
FVector TraceStart;
FVector WorldDirection;
const APlayerController* APC = World->GetFirstPlayerController();
APC->DeprojectScreenPositionToWorld(ViewportPosition.X, ViewportPosition.Y, TraceStart, WorldDirection);
const FVector TraceEnd = TraceStart + WorldDirection * 10000.f;
DrawDebugLine(
GetWorld(),
TraceStart,
TraceEnd,
FColor::Red,
false,
-1,
0
);
}
I think I am mistaking your bIsVertical bool with Y Axis movement?
If I set
ViewportPosition = FVector2D(ViewportSize.X * 0.5, ViewportSize.Y); // Removed * (float)!bIsPositive) as it would of been 0?
Then it does not give any DebugLine that I can see.
But with
ViewportPosition = FVector2D(1.0f * ViewportSize.X, ViewportSize.Y * 0.5); // Added * 1.0f, as bIsPositive would be 1.0?
It keeps the line trace to the Rightside-Centre point when I press D. And top right-ish with I press down. The startline does not appear to be in the middle when going down, only when moving right.