Announcement

Collapse
No announcement yet.

Set actor world location from mouse position math

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Set actor world location from mouse position math

    Hi,

    My math knowledge is quite depressing unfortunately, but I really want to understand the code which I have to control the Actor by dragging it with the mouse. This code also works as the way to place object in the world with mouse click on the screen.

    First of all - the code works great, it is the question more about vector algebra rather than Unreal Engine. I am so lost that I even don't know how to properly name the variables lol

    So, here is the code I've converted from one of the Blueprint examples I found which implements the functionality I need:
    Code:
        FVector WorldLocation;
        FVector WorldDirection;
        PlayerController->DeprojectMousePositionToWorld(WorldLocation, WorldDirection);
    
        // Have no idea how it works but it works! I really need to learn more about vector Algebra :(((
        float DistanceAboveGround = 200.0f;
        float NotSureWhyThisValue = -1.0f;
        float WhyThisOperation = WorldLocation.Z / WorldDirection.Z + DistanceAboveGround;
    
        FVector IsThisNewWorldDirection = WorldDirection * WhyThisOperation * NotSureWhyThisValue;
        FVector ActorWorldLocation = WorldLocation + IsThisNewWorldDirection;            
        // end of "Have no idea how it works" code
        Capsule->SetWorldLocation(ActorWorldLocation);
    If somebody can please explain me why I need to do these operations starring from // Have no idea.. comment line? If I can understand even how to properly name "NotSureWhyThisValue", "WhatDoesItMean", "WhyThisOperation" and "IsThisNewWorldDirection?" that will be a huge improvement for me, the perfect case would be to explain each line though...

    Thanks in advance!

    P.S. I also asked the same question here https://answers.unrealengine.com/que...tion-math.html but no response yet..
    Last edited by paxer; 11-18-2019, 10:37 PM.
Working...
X