Chapter 2 – Getting a real mouse cursor
Now is the time to delve into something easy but fun and visually satisfying. Every game with a mouse needs a cursor. Now I tried several ways of getting a simple mouse cursor to work, but did not end up with good results. UDN has a tutorial on mouse cursor but I was unsuccessful in implementing it properly since I think its for Unreal tech 2. You can find this tutorial here : http://udn.epicgames.com/Two/MouseCursorInterface.html for reference. Anyhow, our cursor will be superior
Create a new file and call it MeshMouseCursor. Make it extends Actor. Actors are the base classes for things that have a 3d representation in your game world. Almost all classes are derived or extended if you prefer from the Actor base class.
This class should look like this :
class MeshMouseCursor extends Actor;
var() StaticMeshComponent Mesh;
DefaultProperties
{
Begin Object Class=StaticMeshComponent Name=MarkerMesh
BlockActors=false
CollideActors=true
BlockRigidBody=false
StaticMesh=StaticMesh'WP_RocketLauncher.Mesh.S_WP_RocketLauncher_Exhaust'
//Materials[0]=MaterialInterface'EngineMaterials.ScreenMaterial'
Scale3D=(X=2.0,Y=2.0,Z=2.0)
Rotation=(Pitch=-16384, Yaw=0, Roll=0)
End Object
Mesh=MarkerMesh
CollisionComponent=MarkerMesh
Components.Add(MarkerMesh)
}
Now the concept of Objects in DefaultProperties are beyond the scope of the tutorial. You should know that they represent components attached to classes. If you have some knowledge of Unity3D they are the same or so then Unity components. If you are familiar with C#, think of them like a button on a form. In this particular exemple I used the RocketLauncher exhaust mesh
I scaled it to twice its size in all axises and rotated so the fire will go up. This makes our 3d cursor, you can change the mesh and play with it, I used a common static mesh that is shipped with UDK just to let it be compilable out of the box. I also commented the Material entry because this comes from a copy/paste of some component in the UTGame and our material is set for our Rocket exhaust automatically.
Wiring the Mouse cursor
Go back into your IsometricGamePlayerController class. Add a new variable after the TraceActor variable :
var MeshMouseCursor MouseCursor; //Hold the 3d mouse cursor
Return to IsometricGamePlayerController::PostBeginPlay() function. We need to spawn the mouse cursor before the game fires up. This is the function that we will use, add this after the Log(“I am alive…” :
simulated event PostBeginPlay()
{
super.PostBeginPlay();
`Log(“I am alive !”);
MouseCursor = Spawn(class‘MeshMouseCursor’, self, ‘marker’);
}
Now the mouse cursor will show up, but it will be located in nowhere land. We should address this, lets make the cursor follow the mouse each frame
Add the following function to that gets executed each frame :
event PlayerTick( float DeltaTime )
{
super.PlayerTick(DeltaTime);
//Set the location of the 3d marker that moves with the mouse.
MouseCursor.SetLocation(MouseHitWorldLocation);
}
Compile and run, you should end up with something like this :

Adding Trace for actors
Remember the TraceActor variable. We could do something with it, now that we have a visible mouse cursor.
Add the following variables on top of MyHud class :
var FontRenderInfo TextRenderInfo; //Font for outputed text to viewport
Lets then override the DrawHUD function to display what object class lies under the mouse cursor :
/**
* This is the main drawing pump. It will determine which hud we need to draw (Game or PostGame). Any drawing that should occur
* regardless of the game state should go here.
*/
function DrawHUD()
{
//local Vector Direction;
local string StringMessage;
//Display traced actor class under mouse cursor for fun
if(IsometricGamePlayerController(PlayerOwner).TraceActor != none)
{
StringMessage = "Actor selected:"@IsometricGamePlayerController(PlayerOwner).TraceActor.class;
}
// now draw string with GoldColor color defined in defaultproperties. note you can
// alternatively use MakeColor(R,G,B,A)
Canvas.DrawColor = MakeColor(255,183,11,255);
Canvas.SetPos( 250, 10 );
Canvas.DrawText( StringMessage, false, , , TextRenderInfo );
}
The StringMessage has a concatenation with the @ inside, what it does is make a space and spit out both the text and the value of TraceActor.class. This is nice to remember when outputing traces in log. You can output pretty much all classes and values this way.
This closes this chapter for the mouse, next we will introduce basic movement.
Chapter 3 – Making the pawn move to our will
Small typing mistake here:
MouseCursor = Spawn(class‘3DMouseCursor’, self, ‘marker’);
Should be MeshMouseCursor
Also, what’s the use of the word ‘marker’ in this line?
Thanks for the great tutorial!
Thanks for the input it has been corrected ! The use of ‘Marker’ is simply a tag for doing fast researching when iterating over a list of actor. You can give this Item a special name and look it up by that name afterward.
hi,
Firstly kudos for making this great tutorial , really appreciate it. i have used this as a base in a personal project of mine.
i have some questions and observations
1. Regarding the Mouse Mesh .. when i try to replace it with any other mesh it doesn’t seem to work properly…
Ive even tried replacing it with 2d textures…
2. Knowing this is a 3d mouse in regards to the mesh attached. i would like to know if its possible to use a 2d mouse
( traditional 2d mouse texture) … De Project its coordinates in the world and use those to perform 3d interactions.
agreed the mesh wouldn’t be able to glide along the 3d surfaces in the world but wouldn’t it work in any case?…
the basic reason for wanting to do something like this is to have this mouse interact with the HUD elements like buttons bars etc..
which would be possible with a 2d mouse mapped to the screen coordinates..
would it be required to use both of them simultaneously by switching between the two or such…
hope ave have conveyed what am trying to do..
About #1, any mesh should work, as long as you set the properties right like scale, rotation and such, the model was set to look acceptable in the tutorial. About setting a 2d texture, you would have to remove the +100 height from the ray casted above the player mesh, enable the debug info to see the blue line from above. To get the 2d texture right remove that +100 again. For using correctly the 2d texture, you would draw it from the HUD so that it is rendered last over the game surface. No depth information will be taken into account there. Be careful to draw your mouse texture as the last hud element else a button or other component could be rendered over it.
Hope it helps you out
hey Roy thanks it does. i completely skipped over the offset value for start trace and i was stumped as to the difference between the 3d mouse mesh and the 2d drawn mouse from the HUD. once again thanks for the quick reply and a great tutorial .