You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would be great to add a Top down rotation mode: "rotate the character towards mouse position" . i added to mine overriding the GetControlRotation on PlayerController to get the mouse position. The code i added:
{
// Get the mouse position on the screen
FVector2D MousePosition;
if (GetMousePosition(MousePosition.X, MousePosition.Y))
{
FVector WorldLocation, WorldDirection;
// Deproject the mouse screen position to a world direction
if (DeprojectScreenPositionToWorld(MousePosition.X, MousePosition.Y, WorldLocation, WorldDirection))
{
// Perform a line trace to find the point in the world where the mouse is aiming
FVector Start = WorldLocation;
FVector End = Start + (WorldDirection * 10000.0f); // Arbitrarily large number to ensure the trace reaches far enough
FHitResult HitResult;
FCollisionQueryParams TraceParams(SCENE_QUERY_STAT(MouseTrace), true);
TraceParams.AddIgnoredActor(GetPawn()); // Ignore the player pawn during the trace
if (GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Visibility, TraceParams))
{
FVector LookAtTarget = HitResult.ImpactPoint;
// Calculate the rotation needed to look at the hit point
FVector Direction = (LookAtTarget - GetPawn()->GetActorLocation()).GetSafeNormal();
return {0.f,Direction.Rotation().Yaw,0.f};
}
}
}
// Fallback to the base control rotation if the mouse position cannot be processed
return Super::GetControlRotation();
}`
This discussion was converted from issue #545 on October 06, 2024 16:30.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Would be great to add a Top down rotation mode: "rotate the character towards mouse position" . i added to mine overriding the GetControlRotation on PlayerController to get the mouse position. The code i added:
Beta Was this translation helpful? Give feedback.
All reactions