Chapter 2 – Setting up for movement
Setting up movement in IsometricGamePlayerController
Copy the following variables to you controller and I will explain in details what each variable is used for :
var Vector2D PlayerMouse; //Hold calculated mouse position (this is calculated in HUD) var Vector MouseHitWorldLocation; //Hold where the ray casted from the mouse in 3d coordinate intersect with world geometry. We will //use this information for our movement target when not in pathfinding. var Vector MouseHitWorldNormal; //Hold the normalized vector of world location to get direction to MouseHitWorldLocation (calculated in HUD, not used) var Vector MousePosWorldLocation; //Hold deprojected mouse location in 3d world coordinates. (calculated in HUD, not used) var Vector MousePosWorldNormal; //Hold deprojected mouse location normal. (calculated in HUD, used for camera ray from above) /***************************************************************** * Calculated in Hud after mouse deprojection, uses MousePosWorldNormal as direction vector * This is what calculated MouseHitWorldLocation and MouseHitWorldNormal. * * See Hud.PostRender, Mouse deprojection needs Canvas variable. * * **/ var vector StartTrace; //Hold calculated start of ray from camera var Vector EndTrace; //Hold calculated end of ray from camera to ground var vector RayDir; //Hold the direction for the ray query. var Vector PawnEyeLocation; //Hold location of pawn eye for rays that query if an obstacle exist to destination to pathfind. var Actor TraceActor; //If an actor is found under mouse cursor when mouse moves, its going to end up here.
PlayerMouse
Each frame the mouse position will be aquired in the MyHud::PostRender function. It is not much relevant to keep the variable inside the controller per se, but since all variables for calculating mouse are located here, we might as well group them, since the controller is pretty much available to all classes in the game, it might be usefull one day.
MouseHitWorldLocation
This variable holds the vector of a calculated Raytrace (Trace function) in the MyHud::PostRender function. Think of it has the point in 3d where the mouse hit a geometry object. This variable represent the point where the mouse exist in 3d coordinate and will be extensively used to make the pawn move.
MouseHitWorldNormal
This variable is a pre-calculated normalized vector of where the mouse hit the geometry. This is used for advanced effects and will not be of much use in this tutorial, but we keep it for advanced math related to mouse position in 3d world space. Again this is calculated from the MyHud::PostRender function.
MousePosWorldLocation
This variable will hold the deprojected 2d mouse coordinates. Basically from the transposition of a pixel in 2d space to 3d coordinates. We will we not use this variable much, we are more interested in the direction vector than the actual location. You should always use MouseHitWorldLocation in preference to this variable. We keep it for futur references also.
MousePosWorldNormal
This is the second most important variable in the mouse calculations. It calculates the direction in which the deprojection goes. This might be advanced if your not very good with vector math. You should know that we will use this direction to cast a ray from the camera to have precise mouse 3d coordinates.
StartTrace, EndTrace and RayDir
These variables will hold the result of the ray cast from the camera to know where the mouse intersects with 3d geometry. They are kept in the controller for futur references.
PawnEyeLocation
This variable is used to calculate a ray in direction of the pawns eye to see if movement in straight line to mouse click would cause a collision. If no obstacles are detected with tha FastTrace function, then the pawn can simply move without using Path-finding.
TraceActor
This variable will keep a reference to what would be hit under the mouse ray at each frame. So when you move the mouse over an actor or geometry, you could show a special effect in the hud at the position of the actor. We will leave advanced functions out of this tutorial for this variable, but I am sure you will find plenty of stuff to do like pop-ups and game play information.
Compile to check for errors, everything should be in place to proceed to create the debug information for the mouse position.
Creating a console function
To help get debug information ON/OFF for our tutorial we will create a console function that you will be able to call inside the game console when the game is running. To do so we simply use the keyword exec before a function. Copy the following inside your MyHud class :
/******************************************************************
* TUTORIAL FUNCTION
*
* Declare a new console command to control debug of 3d line
* debug drawing. This will also control of showing the paths
* the pawn will have available into its calculated routes.
*
******************************************************************/
exec function ToggleIsometricDebug()
{
bDrawTraces = !bDrawTraces;
if(bDrawTraces)
{
`Log("Showing debug line trace for mouse");
}
else
{
`Log("Disabling debug line trace for mouse");
}
}
You will also have to declare at the top of your hud class this variable :
var bool bDrawTraces; //Hold exec console function switch to display debug of trace lines & Paths.
- Compile the project and hit run
Once inside the game, push TAB key and the console will apear. Type in the name of the function : “ ToggleIsometricDebug” and hit Enter, you should see the log in the console. For now it only set the variable on/off. Lets add visuals to this.
Add this to your Hud class :
/*******************************************************************
* TUTORIAL FUNCTION
*
* Helper trace for you to visually see where collision and tracing
* extend to.
*
*******************************************************************/
function DrawTraceDebugRays()
{
local IsometricGamePlayerController IsoPlayerController;
IsoPlayerController = IsometricGamePlayerController(PlayerOwner);
//Draw Trace from the camera to the world using
Draw3DLine(IsoPlayerController.StartTrace, IsoPlayerController.EndTrace, MakeColor(255,128,128,255));
//Draw eye ray for collision and determine if a clear running is permitted(no obstacles between pawn && destination)
Draw3DLine(IsoPlayerController.PawnEyeLocation, IsoPlayerController.MouseHitWorldLocation, MakeColor(0,200,255,255));
}
This function will draw 3d lines with the calculated variables in MyHud::PostRender. To effectively use this function we will add a few lines inside MyHud::PostRender function, just after DrawHud();
…
//Your basic draw hud routine
DrawHUD();
if(bDrawTraces)
{
//If display is enabled from console, then draw Pathfinding routes and rays.
super.DrawRoute(Pawn(PlayerOwner.ViewTarget));
DrawTraceDebugRays();
}
Compile and run the game, again type the console command “ ToggleIsometricDebug” to now see the two rays. The blue one, is the ray to see if the path is blocked. This ray originates from the pawns eyes. The second one coming from heaven is the camera ray to get the mouse location.

NOTE : the super.DrawRoute(Pawn(PlayerOwner.ViewTarget)); is not displaying anything for the moment because we do not call any routine to find a path. Leave it there it will come handy later.
NOTE 29 JANUARY 2010
If at some point after this tutorial you want to enable a textured mouse cursor, you will want to remove the +100 Y when you trace because it will offset your mouse cursor. For now this tutorial use a 3d mouse model put at the collision point with the ground.
NOTE 25 March 2010
You should experience a difference of height between the pawns feet and the floor, you can look up the reasons and solutions to this problem right here : http://utforums.epicgames.com/showthread.php?t=721942
Chapter 2 – Getting a real mouse cursor
I’ve followed through the tutorials so far and mostly its going well, I did think as soon as i’d set up the camera that there was a problem though, it really wasn’t isometric. The camera is basically just above the guys head and so you can only see the character if you look right down. After seeing the picture at the end of this page i realised that something is deffinatly wrong with what i’ve got. I thought it might be that the values in Loc.X Loc.Y and Loc.Z were too low so i changed these but there was no difference. Have you any idea what the problem could be? I’m using the april beta of udk. I also downloaded the source files for chapter 1 and replaced my code with that in there. It still didn’t work right.
@Matthew
Not to worry, I sorted it with a clean install. I think the problem was my previous attempts at camera manipulation
@Matthew
have you tried it with the may 2010 udk? hoo boy, it gets really wierd then! lol.
@Neurosys
about to try it with the may build. what should i expect?