Announcement

Collapse
No announcement yet.

[SOLVED] Mouse location to world space

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

    [SOLVED] Mouse location to world space

    Is there any way i can get my mouse position converted to world space? I have this Blueprint setup but its not working. I mean the XYZ is limited in 0-1 range.

    Attached Files
    Unreal Issue Tracker - Desktop App for Unreal Engine Issues
    Unreal Nexus - Create Share and Experience!

    Unreal Engine 4 World-Wide User Map

    [PLUGIN] Aws Gamelift Client Plugin
    [TOOL] Create your own binary release of UE4 from GitHub source
    [Marketplace] Vehicle Soccer Template
    [Marketplace] Objective Waypoint System
    My UE4 Tutorials and Misc Tools

    Lead Programmer at YetiTech Studios
    Your Friendly Neighborhood
    Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

    #2
    The cursor position doesn't exist in 3d space, so what I think you'll want to do is get the position of the mouse cursor and then run a line trace from it to see what object is under the cursor, then return that position.
    Trevor Lee

    Comment


      #3
      Originally posted by Hyperloop View Post
      get the position of the mouse cursor
      Well thats the problem. Get Mouse Position node from Player Controller is in 0-1 range. Theres another node called Convert Mouse Location to World Space but it doesnt seem to work either.
      Unreal Issue Tracker - Desktop App for Unreal Engine Issues
      Unreal Nexus - Create Share and Experience!

      Unreal Engine 4 World-Wide User Map

      [PLUGIN] Aws Gamelift Client Plugin
      [TOOL] Create your own binary release of UE4 from GitHub source
      [Marketplace] Vehicle Soccer Template
      [Marketplace] Objective Waypoint System
      My UE4 Tutorials and Misc Tools

      Lead Programmer at YetiTech Studios
      Your Friendly Neighborhood
      Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

      Comment


        #4
        Convert Mouse Location to World Space does work, but you'll need to do some tracing to get anything out of it. I believe one of the Blueprint examples shows this, but if not I think I have something working on one of my other machines, which I'll have a look at later.

        Projection and Deprojection is a bit fecked in BP right now, unfortunately.

        Comment


          #5
          Originally posted by ambershee View Post
          I believe one of the Blueprint examples shows this
          You mean the Mouse Interface Example?

          Originally posted by ambershee View Post
          I think I have something working on one of my other machines, which I'll have a look at later.
          That will be a huge help Ambershee. Could you please share an example screenshot?

          Originally posted by ambershee View Post
          Projection and Deprojection is a bit fecked in BP right now, unfortunately.
          Projection seems to do the job. I have the player name and objective markers projected onto the screen.
          Unreal Issue Tracker - Desktop App for Unreal Engine Issues
          Unreal Nexus - Create Share and Experience!

          Unreal Engine 4 World-Wide User Map

          [PLUGIN] Aws Gamelift Client Plugin
          [TOOL] Create your own binary release of UE4 from GitHub source
          [Marketplace] Vehicle Soccer Template
          [Marketplace] Objective Waypoint System
          My UE4 Tutorials and Misc Tools

          Lead Programmer at YetiTech Studios
          Your Friendly Neighborhood
          Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

          Comment


            #6
            I just worked on this same thing.

            The node Convert Mouse Location to World Space does what it is supposed to... but it takes its location from the "slice" in space that is the camera window.

            It however also gives you a direction. So to get a point, take the "world direction" from the node, multiply it by... say 1000, then add that result to the "world location" from the node. You now have a point 1000 units from the point you clicked.

            I have done this, in a bit more elaborate way to spawn some object at "water level" (z = 0) under the mouse cursor.Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	129.8 KB
ID:	1050770
            Last edited by Rasped; 05-22-2014, 03:06 AM.
            Easy weapons in Unreal Engine 4:
            Check out Realistic Blueprint Weapons

            Currently doing a tutorial series on Vectors and what they are good for.
            Please visit Unreal Unscripted

            Comment


              #7
              Originally posted by Rasped View Post
              So to get a point, take the "world direction" from the node, multiply it by... say 1000, then add that result to the "world location" from the node. You now have a point 1000 units from the point you clicked.
              Thank you very very much Rasped! . This works like a charm.
              Unreal Issue Tracker - Desktop App for Unreal Engine Issues
              Unreal Nexus - Create Share and Experience!

              Unreal Engine 4 World-Wide User Map

              [PLUGIN] Aws Gamelift Client Plugin
              [TOOL] Create your own binary release of UE4 from GitHub source
              [Marketplace] Vehicle Soccer Template
              [Marketplace] Objective Waypoint System
              My UE4 Tutorials and Misc Tools

              Lead Programmer at YetiTech Studios
              Your Friendly Neighborhood
              Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

              Comment


                #8
                Originally posted by ryanjon2040 View Post
                Thank you very very much Rasped! . This works like a charm.

                No problem, I'm happy that it worked for you
                Easy weapons in Unreal Engine 4:
                Check out Realistic Blueprint Weapons

                Currently doing a tutorial series on Vectors and what they are good for.
                Please visit Unreal Unscripted

                Comment


                  #9
                  This could be converted to a snazy fast BPNode function right?
                  Something along the line of GetMousePositionInWorld with a vector3 out?

                  Comment


                    #10
                    Sorry for the necro but thanks alot Rasped, this fixed an issue I had as well.

                    Comment


                      #11
                      Nice! looking to do a set up similar to this.

                      Comment


                        #12
                        Or, because handling gameplay mechanics like input through the HUD is pants-on-head-pencils-up-the-nose retarded, you could use this code in your own project to give you projection / deprojection functions you can use from anywhere:

                        Code:
                        FVector UMyGameplayStatics::Project(UObject* WorldContextObject, FVector Location)
                        {
                        	FPlane V(0, 0, 0, 0);
                        	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
                        	ULocalPlayer* LocalPlayer = GEngine->GetLocalPlayerFromControllerId(World, 0);
                        
                        	FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(LocalPlayer->ViewportClient->Viewport, World->Scene, LocalPlayer->ViewportClient->EngineShowFlags).SetRealtimeUpdate(true));
                        
                        	FVector OutViewLocation;
                        	FRotator OutViewRotation;
                        	FSceneView* SceneView = LocalPlayer->CalcSceneView(&ViewFamily, OutViewLocation, OutViewRotation, LocalPlayer->ViewportClient->Viewport);
                        
                        	if (SceneView != NULL)
                        	{
                        		Location.DiagnosticCheckNaN();
                        		V = SceneView->Project(Location);
                        	}
                        
                        	FVector2D ScreenDimensions;
                        	LocalPlayer->ViewportClient->GetViewportSize(ScreenDimensions);
                        
                        	FVector resultVec(V);
                        	resultVec.X = (ScreenDimensions.X / 2.f) + (resultVec.X*(ScreenDimensions.X / 2.f));
                        	resultVec.Y *= -1.f * GProjectionSignY;
                        	resultVec.Y = (ScreenDimensions.Y / 2.f) + (resultVec.Y*(ScreenDimensions.Y / 2.f));
                        
                        	// if behind the screen, clamp depth to the screen
                        	if (V.W <= 0.0f)
                        	{
                        		resultVec.Z = 0.0f;
                        	}
                        	return resultVec;
                        }
                        
                        void UMyGameplayStatics::Deproject(UObject* WorldContextObject, FVector2D ScreenPos, /*out*/ FVector& WorldOrigin, /*out*/ FVector& WorldDirection)
                        {
                        	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
                        	ULocalPlayer* LocalPlayer = GEngine->GetLocalPlayerFromControllerId(World, 0);
                        
                        	FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
                        		LocalPlayer->ViewportClient->Viewport,
                        		World->Scene,
                        		LocalPlayer->ViewportClient->EngineShowFlags)
                        		.SetRealtimeUpdate(true));
                        
                        	FVector OutViewLocation;
                        	FRotator OutViewRotation;
                        	FSceneView* SceneView = LocalPlayer->CalcSceneView(&ViewFamily, OutViewLocation, OutViewRotation, LocalPlayer->ViewportClient->Viewport);
                        
                        	if (SceneView != NULL)
                        	{
                        		SceneView->DeprojectFVector2D(ScreenPos, /*out*/ WorldOrigin, /*out*/ WorldDirection);
                        	}
                        }

                        Comment


                          #13
                          Originally posted by Rasped View Post
                          I just worked on this same thing.

                          The node Convert Mouse Location to World Space does what it is supposed to... but it takes its location from the "slice" in space that is the camera window.

                          It however also gives you a direction. So to get a point, take the "world direction" from the node, multiply it by... say 1000, then add that result to the "world location" from the node. You now have a point 1000 units from the point you clicked.

                          I have done this, in a bit more elaborate way to spawn some object at "water level" (z = 0) under the mouse cursor.[ATTACH=CONFIG]3515[/ATTACH]
                          but how to do if z not 0, and z=1000?
                          Not correct if just "world direction" multiply by 1000.
                          Not understand!!

                          Comment


                            #14
                            im use:
                            Click image for larger version

Name:	Снимок экрана (9).png
Views:	2
Size:	81.7 KB
ID:	1076480
                            how to fix that?
                            Click image for larger version

Name:	Снимок экрана (13).png
Views:	2
Size:	513.0 KB
ID:	1076481
                            Click image for larger version

Name:	Снимок экрана (14).png
Views:	2
Size:	497.9 KB
ID:	1076482
                            Last edited by aGosh; 05-16-2015, 09:40 AM.

                            Comment


                              #15
                              I know this is a ridiculously late reply, but thank you so much! This just solved the exact problem I had for the past hours and I knew there had to be a simple solution. Thank you once again!

                              Comment

                              Working...
                              X