View Full Version : Tracing - mouse position to world
Hi All
How to make StartTrace of mouse coordinates on the screen, instead of from the center (as by default - from POV location)?
sorry for my English
TheSpaceMan
11-20-2009, 06:19 AM
Depends on where you try to get the Mouse coords from. Try do a in file search from MouseX maybe it will return something useful.
I was incorrectly expressed a little. How to convert a cursor position to world coordinates, being based on a camera position?
JeremyStieglitz
11-20-2009, 04:54 PM
What you're referring to is generally called Unprojection or Deprojection ( http://wiki.beyondunreal.com/UE3:Canvas_(UT3)#DeProject ).
You can do it this way:
Assuming you're in a HUD class (to easily get the UI SceneClient, though there are other ways to get access to this, such as UIScene.SceneClient if you are using a UI):
function vector2D GetMouseCoordinates()
{
local Vector2D mousePos;
local UIInteraction UIController;
local GameUISceneClient GameSceneClient;
UIController = PlayerOwner.GetUIController();
if ( UIController != None)
{
GameSceneClient = UIController.SceneClient;
if ( GameSceneClient != None )
{
mousePos.X = GameSceneClient.MousePosition.X;
mousePos.Y = GameSceneClient.MousePosition.Y;
}
}
return mousePos;
}
//Canvas is only valid during PostRender phase
event PostRender()
{
local Vector WorldOrigin;
local Vector WorldDirection;
Canvas.DeProject(GetMouseCoordinates(),WorldOrigin ,WorldDirection);
//now you have the world origin and direction vector of the mouse deprojection
//so you can do with it whatever you'd like, such as do a Trace with it to see what the mouse is pointing at
}
Another useful Canvas function is Project(), which turns a World coordinate into a screen coordinate, useful for drawing HUD elements on top of your Actor's positions, etc.
Cheers,
Jer
It is very grateful, I have achieved result
TheSpaceMan
11-22-2009, 06:15 PM
Thanks. That was actually my next step as well.
LordsWarrior
11-22-2009, 08:41 PM
Hi
I want to do this for a diablo style movement. (Eg Point the mouse and click to move the character).
In this case should I be doing all this inside my Derived player controller class?
Also...how do I actually free up the mouse, as I currently lose it (I havent got far in UDK yet..so Im still in U3 mod mode.)
Thanks...and Thanks Jeremy for the info above
-LW
JeremyStieglitz
11-22-2009, 10:54 PM
The easiest way I know of (and perhaps the only way within the UDK) to show the mouse is to open a UI scene that has DisplayMouse set to true in its properties. You can open a UI scene through code, using "class'UIRoot'.static.GetSceneClient().OpenScene(.. ..);"
... Or most easily through Kismet using the OpenScene action.
As for Diablo style movement, meaning moving towards the last place that the player clicked:
In the StartFire PlayerController event (i.e. when the player clicks the mouse button), you should calculate and store the location that your "Deprojected" Trace collided with:
Trace(TargetLocation,TraceHitNormal,MouseProjectio nOrigin + MouseProjectionDirection*50000,MouseProjectionOrig in,false);
You can probably use LocalPlayer(Player).DeProject() in your PlayerController to calculate the Deprojection values... however, the last time I tried using that version of the function, it did not give me correct results.
So if that LocalPlayer.DeProject() function doesn't work for you, then just store the last Deprojected WorldOrigin and WorldDirection in your HUD's PostRender() function (as I've indicated in my response above), and access those in the PlayerController (using its 'myHUD') to do the Trace.
Then, in the your PlayerController's PlayerMove function, calculate the "NewAccel" to be Normal(TargetLocation - Pawn.Location). There you should probably also set the Pawn's Desired Rotation (using SetDesiredRotation) to look towards that direction as well.
-Jer
LordsWarrior
11-23-2009, 03:57 AM
HI Jeremy....again
Forgive my newness please
So in kismit I set to open a UI scene and in the content browser I have made a scene.
It shows the arrow now...but pretty much locks everything. It isnt paused but I cant do anything when its open.
What do I need in the UI scene. I'd assume its fairly empty scene as we jsut want it open for mouse enable?
Cheers
-LW
feanix
11-23-2009, 06:15 AM
I'm not at a computer with UDK atm, but isnt there something in the scene's properties (around where you disable pausing) about flushing controls? Untick that, maybe? Let us know if it works!
TheSpaceMan
11-23-2009, 06:19 AM
I got confused for a second, then I remembered a part mentioned in the third person tutorial. The pause of the scene is a effect of the UI you created. If you open up your uiscene in the uieditor, select nothing and just go trough the properties, there is a pause on open thingie. Hope that made any sense.
Aka, there is a Pause on display box in the Scene Settings in the UI Editor, un tick that box and stuff should work.
LordsWarrior
11-23-2009, 02:56 PM
I got confused for a second, then I remembered a part mentioned in the third person tutorial. The pause of the scene is a effect of the UI you created. If you open up your uiscene in the uieditor, select nothing and just go trough the properties, there is a pause on open thingie. Hope that made any sense.
Aka, there is a Pause on display box in the Scene Settings in the UI Editor, un tick that box and stuff should work.
Nah its not the pause. I had tried that . You can see the game in the background playing but with the UIscene loaded it disables everything else.
Basically Im wanting to have the game playing AND a mouse cursor available.
-LW
TheSpaceMan
11-23-2009, 03:03 PM
Ah. There is probably a setting if your scene as well if it should absorb all your input, or if it should be done before or after the scene.
rahatropa
11-23-2009, 06:48 PM
I believe SpaceMan is right.. in your UIScene properties you should set the PauseOnWhatever to be false and DisableInput to false (I apologize those are not the correct names but what came to my head), if you want a mouse cursor you would want to enable that property. This will in essence act as a HUD that allows interaction during gameplay.
JeremyStieglitz
11-24-2009, 02:47 AM
It shows the arrow now...but pretty much locks everything. It isnt paused but I cant do anything when its open.
What do I need in the UI scene. I'd assume its fairly empty scene as we jsut want it open for mouse enable?
Cheers
-LW
-------------
Ah yeah sorry I forgot to mention, here are the Scene Flags I recommend to use so that the UI unlocks input:
Pause Game While Active=false (of course ;)
Capture Matched Input=false
Flush Input=false
Scene Input Mode=InputMode_None
Never Focus=true (so that it doesn't interefere with other UI's you may be displaying)
I also recommend setting:
Always Render Scene=true (so that it's not affected by other UI's you may have open)
Exempt from Auto Close=true (same thing, so that it doesn't automatically close if you close another UI)
Cheers,
Jer
LordsWarrior
11-25-2009, 03:41 AM
OH!! Someone made a great tutorial here!!
http://forums.epicgames.com/showthread.php?t=709361
-LW
LordsWarrior
11-28-2009, 12:43 AM
and access those in the PlayerController (using its 'myHUD') to do the Trace.
-Jer
How to I make myModPlayerController , get info from myModHud
when I try to use myModPlayerController's .myHud it is using a type HUD not mu "myModHud type.
ie I cant go (in myModPlayerController)
Var myModHud theHud;
theHud = myHud;
I need this as I have added some new functions to myModHud I need to access from playerController
Do I need to typeCast some how even tho myModHud is derived from HUD (via GameHud)
Cheers
-P
Try this - in your Player Controller: CustomGameHUD(MyHud).[function/variable]
TheSpaceMan
11-28-2009, 10:36 AM
Try this - in your Player Controller: CustomGameHUD(MyHud).[function/variable]
Yeah just cast it too your own ui type, but be sure that you actually get something so you don't try to access None.
marcusmattingly
11-28-2009, 07:40 PM
I am pretty sure there is a checkbox for UIScene that says something like "Pause game when visible" or something to that effect.
TheSpaceMan
11-29-2009, 09:45 AM
It shows the arrow now...but pretty much locks everything. It isnt paused but I cant do anything when its open.
What do I need in the UI scene. I'd assume its fairly empty scene as we jsut want it open for mouse enable?
Cheers
-LW
-------------
Ah yeah sorry I forgot to mention, here are the Scene Flags I recommend to use so that the UI unlocks input:
Pause Game While Active=false (of course ;)
Capture Matched Input=false
Flush Input=false
Scene Input Mode=InputMode_None
Never Focus=true (so that it doesn't interefere with other UI's you may be displaying)
I also recommend setting:
Always Render Scene=true (so that it's not affected by other UI's you may have open)
Exempt from Auto Close=true (same thing, so that it doesn't automatically close if you close another UI)
Cheers,
Jer
The problem I got now is that, Input mode none, allows the input to reach the player controller. The problem is that now I can't click the buttons. If i set the input to matching only i can interact with the gui but not the game.
What I need is to make the gui only catch the input if it's actually over the UI objects, not over the empty areas...
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.