Archive

Archive for November, 2009

UDK tutorial : Mouse cursor with basic HUD

November 24, 2009 9 comments

In my last UDK tutorial. We saw how to get basic isometric camera up and running. To get things into motion for full RTS or Isometric game, you will need persistent mouse cursor so you can actually click somewhere usefull inside the game. This tutorial will not yet cover how the mouse click is handled for movement but I will give you a basic setup so you can do some research on your own (Nothing like it if you really want to get some UnrealScript coding skills).

First of all you will add a new script file in visual studio inside your Classes folder for your project. Again if you are unsure how to do this, look into this post, or this thread. Now name your new script file with the name appended name “Hud” for clarity ex : “MyModHud”.

You should have the following code :

class MyModHud extends Object;

DefaultProperties
{
}

Now you will change the extends of the class to reflect something like :

class MyModHud extends GameHUD
	config(Game);

Now the function you will want to have to get basic mouse coordinate is the following (put it between class declaration and DefaultProperties.

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;
}

What it does is basically get the User Interface Controller and set the mouse X and Y. Now to get a proper Heads Up Display running in UDK, you will need to override the PostRender function. In the PostRender function you will prepare all the display position and work before rendering it to screen. It will be PostRender that will call DrawHud (Where the rendering to screen actually go). DrawHud is considered as the main drawing pump. The variable Canvas will only be valid during PostRender and that is why we call the DrawHud function from it.

Before we actually add those two functions, we need a couple of variables on top of our class :

var Vector WorldOrigin;
var Vector WorldDirection;

var FontRenderInfo TextRenderInfo;

var Texture2D    CursorTexture;

/** Various colors */
var const color GoldColor;

var Vector2D    MousePosition;

WorldOrigin will hold where our mouseclick occured in world unit.
WorldDirection will hold the direction of the ray that is cast to the world for de-projection

TextRenderInfo will hold extra information on drawing text on screen for debug purpose.
CursorTexture will hold a reference to the cursor texture will will plot to screen.
GoldColor will hold a sample gold color for rendered text on screen
MousePosition will hold where the mouse is hovering during play.

With those variables on top we need to set the default properties for some of them and so go inside the DefaultProperties brackets and put the following :

DefaultProperties
{
	CursorTexture=Texture2D'UI_HUD.HUD.UTCrossHairs'
	GoldColor=(R=255,G=183,B=11,A=255)
	TextRenderInfo=(bClipText=true)
}

Now you will put the rest inside the class just before the DefaultProperties :

//Canvas is only valid during PostRender phase
event PostRender()
{
	MousePosition = GetMouseCoordinates();
        //Deproject the mouse from screen coordinate to world coordinate and store World Origin and Dir.
	Canvas.DeProject(MousePosition, 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
	DrawHUD();
}

/**
 * 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 string StringMessage;
	StringMessage = "MouseX" @ MousePosition.X @ "MouseY" @ MousePosition.Y @ "World" @ WorldOrigin @ "WorldDir" @ WorldDirection;
	// now draw string with GoldColor color
	Canvas.DrawColor = GoldColor;
	Canvas.SetPos( 10, 10 );
	Canvas.DrawText( StringMessage, false, , , TextRenderInfo );

        //Set position for mouse and plot the 2d texture.
	Canvas.SetPos(MousePosition.X, MousePosition.Y);
	Canvas.DrawTile(CursorTexture, 26 , 26, 380, 320, 26,26);
}

The code is pretty explicit in itself, you can get the final file here.

The last operation to do, to make your hud be actually used by your game is to set it properly inside your gameInfo class.

defaultproperties

{

    ...

    HUDType=class'MyMod.MyModHud'

    ...

}
Update me when site is updated
Categories: UDK

UDK Isometric Camera tutorial

November 23, 2009 2 comments

This tutorial is following the recent posting here that contains basic links to learn how to set up visual studio with nfringe to get started on coding unreal scripts (EDIT : You can now have a real help in setting up everything right here). Now you could use Kismet to produce the same result as the following unrealscript but the Kismet script will have to be contained within a level. This does not make practical the fact that most of the time the camera will most certainly be the same in an RTS or RPG isometric game.

What will be covered in this tutorial

  • Basic Game main class
  • Basic Game Controller
  • Basic Camera for defaulting to 3rd person
  • Basic Pawn definition for the main player

What will not be covered in this tutorial

  • Click on the map
  • Any mouse interactions
  • Pawn rotation and basic A.I.

udk_iso

The first Thing we will cover, will be the main game class. If you are starting out fresh and do not want support for Unreal Deathmatch, you will want to use GameInfo as a base class for your game.

class MyGameInfo extends GameInfo;

defaultproperties
{
	bDelayedStart=false
	PlayerControllerClass=class'MyMod.MyPlayerController'
	DefaultPawnClass=class'MyMod.MyPawn'

	Name="Default__MyGameInfo"
}

Now the declared default properties help initialize basic variables akin to what you would do in any Property Editor except they are hardcoded in text. Both declared classes are to inform the UDK framework with which classes this game should work for the player controller (where the player code and interactions are located) and the pawn class that represent physically the player in the world. I Suggest you do look at the classes this tutorial expands on, as it will give you unvaluable insight on what is used when. So that is it for the base game class. Remember that you should declare it correctly inside UTEngine.ini and UTGame.ini (see the tutorial referenced above if you are not knowledgable about that.)

class MyPlayerController extends PlayerController
	config(Game);

function UpdateRotation( float DeltaTime )
{
	local Rotator	ViewRotation;

	ViewRotation.Pitch = (-45.0f * DegToRad) * RadToUnrRot;
	ViewRotation.Yaw = (-45.0f * DegToRad) * RadToUnrRot;

	SetRotation(ViewRotation);
}

defaultproperties
{
	CameraClass=class'MyMod.MyPlayerCamera'
}

Now this one is pretty interesting. Its the basic player controller. Normally, you would put all code that pertains to game movement, menu handling and such in this controller. It will have a very close relationship with the custom game pawn bellow. We have overriden the UpdateRotation function because it is exactly here that we will force the 3rd person camera to be in a specific angle. Now Unreal has a very perticular way of treating rotations. They amount to a an integer (-65537 to 65537) where 65537 is equal to 360 degree. You could simply put your angle in there to save the calculus in each frame, but it is nice to know how to specify it in human readable format. You can look the DegToRad constant and RadToUnrRot in Object.uc. It should look as follow :

const MaxInt		= 0x7fffffff;
const Pi			= 3.1415926535897932;
const RadToDeg		= 57.295779513082321600;	// 180 / Pi
const DegToRad		= 0.017453292519943296;		// Pi / 180
const UnrRotToRad	= 0.00009587379924285;		// Pi / 32768
const RadToUnrRot	= 10430.3783504704527;		// 32768 / Pi

On to the camera and default properties of 3rd person. Now UDK has a very good third person camera. It would be a shame not to use it to its full potential. you will see with some default properties, you can smooth out cam movement without a single line of code added.

class MyPlayerCamera extends GamePlayerCamera;

protected function GameCameraBase FindBestCameraType(Actor CameraTarget)
{
	return ThirdPersonCam;
}

defaultproperties
{
	ThirdPersonCameraClass=class'MyMod.MyThirdPersonCamera'
}

The FindBestCameraType will always force a return of the 3rd person camera.

class MyThirdPersonCamera extends GameThirdPersonCamera;

DefaultProperties
{
	ThirdPersonCamDefaultClass=class'MyMod.MyThirdPersonCameraMode_Default'
}

The MyThirdPersonCamera simply exist to specify our implementation of _Default values declared as follow:

class MyThirdPersonCameraMode_Default extends GameThirdPersonCameraMode_Default;

var float FOV;

function float GetDesiredFOV( Pawn ViewedPawn )
{
	return FOV;
}

DefaultProperties
{
	FOV=90.f;
	TargetRelativeCameraOriginOffset=(x=-192,y=192,z=192)
	bLockedToViewTarget=TRUE
	bFollowTarget=FALSE
	bInterpLocation=TRUE
	bInterpRotation=TRUE
	bSkipCameraCollision=TRUE
	BlendTime=0.75
}

The DefaltProperties are what will make the camera interpolate on the movement of the Pawn. The offset will permit you to specify a default height. Like I said at the beginning, this is to start you up, you should look in the forum to implement the mouse cursor and such. I will probably do a part 2 of this tutorial when I find out more about it.

Hope it helps people out !

you can follow it up here on the forum

Update me when site is updated
Categories: UDK

App store discontent rising to new heights

November 19, 2009 Comments off

Apple’s control over the App Store—which seems arbitrary at times—still frustrates developers. That much isn’t a surprise, but some developers have become frustrated to the point that they have decided to simply halt iPhone development altogether. Facebook’s Joe Hewitt, Second Gear’s Justin Williams, and long-time Mac software developer Rogue Amoeba have all recently decided that enough is enough, and the loss of these developers and others could spell a troubling future for the App Store. True, it has over 100,000 applications, but how many of them are created with the kind of care and passion we take for granted in the Mac software world?

Read the whole story here at Ars Technica

Update me when site is updated
Categories: Politics, Technology

Air operated lasers a reality

November 19, 2009 Comments off

Most of us did think it was in the working. Its not real until you see it in action here

Quote : “Boeing and the U.S. Air Force have been busy this summer testing the Advanced Tactical Laser, a high-power directed energy weapon mounted on a C-130H Hercules transport.

In this August 30 test at New Mexico’s White Sands Missile Range , the laser was fired at a target for the first time, with the following result. (Later footage of the laser “defeating” the target, or rendering it completely inoperable, is not yet available.)”

Update me when site is updated
Categories: Politics, Technology

Bernard Landry speaks at MGS

November 18, 2009 Comments off

Former Quebec Premier Bernard Landry has dubbed tax credits implemented for multimedia development companies in the Canadian province as an enormous success, reports The Montreal Gazette.

Landry (pictured left), speaking at the Montreal International Games Summit, claimed that the initiative also helped change Quebec’s economic makeup, stating, “Thirty years ago, our main exports were minerals, hydro-electricity and lumber. Today, we export airplanes, train parts, and video game.”

Of course Landry is also credited as introducing the tax scheme, which currently refunds qualified companies up to 37.5 percent of labor costs. Landry claimed that the cost of the program to taxpayers was earned back in five years.

Update me when site is updated
Categories: Politics