Friday, March 18, 2011

UDK Scripting = You are WinRar (Winner)

Alright, I'm fairly new to scripting but finally picked up some tweaks today and things are definitely looking on the bright side!

So, that being said. There's a series of changes that are required to complete that 'side-scroller ' game concept that are fairly simple, but a total struggle to try and track down if you're new to this.

So essentially, we're going to start up UDK and let it all load. Start building your base level (player start, lighting, and something to stand on).

Next we're going to position the camera.

So click on "View" at the top and branch out to Browser Windows>>Actor Classes.

Once the window pops up, you'll be met with a variety of classes. (See figure 1.1)

From Tutorial Files




//Tip: Use spacebar to switch between Translate/Scale/Rotate modes in the viewport//
Create your camera actor and position/angle according to where you want it to point (typically the Player). And then hit the "K" icon on the top bar. This will open the Kismet Editor.

Now, I'm not going to get too specific into the parts you need, but be aware that if you click on an object then right click in Kismet, it shows the option "New Object var using "_Object_name_".

This creates a variable for connecting your object to nodes, but in this sense, the "Camera_Actor0" will probably be the only one you need.

So I'll just throw you a screenshot (See figure 1.2) of how you should lay out your Kismet graph to position the camera. Unfortunately, you'll have to figure out where these objects sit since I'm running out of time to compose this quicky tutorial.

From Tutorial Files




Since this is laid out you'll find that when you build and start your game, you'll have a sidescroller view. But the gun shoots terribly off kilter, your player is looking around funny, etc etc... And worst of all, they key binding is terrible!

This is composed in our scripts sets. So redirect yourself to the UDK install folder and we're going to start at:

C:\UDK\UDK-2011-01\Development\Src\UTGame

Open: UTPlayerController.uc using notepad or any text applicable application.

We're going to search for this code set. Add in the red text right after this.

function Rotator GetAdjustedAimFor( Weapon W, vector StartFireLoc )
{
local vector FireDir, HitLocation, HitNormal;
local actor BestTarget, HitActor;
local float bestAim, bestDist, MaxRange;
local rotator BaseAimRot;

return Pawn.Rotation;

This will force your mouse to no longer have input in the direction that the gun fires, it will simply fire straight from where the player's character is facing.

Next, we're going to vary the direction the player faces (in this case, directly forward).

I'm just going to copy and paste the code in the same file that you want to reference.

Where the "\\" sets have been implemented, it's simply to 'comment' out the code so it does NOT compile, but I strongly suggest you don't destroy it. Again, red text is what we add.

function UpdateRotation( float DeltaTime )
{
local rotator DeltaRot;

ClientMessage("This code is running in UTPlayerController!");

if (bDebugFreeCam)
{
// Calculate Delta to be applied on ViewRotation
//DeltaRot.Yaw = PlayerInput.aTurn;
//DeltaRot.Pitch = PlayerInput.aLookUp;
//ProcessViewRotation( DeltaTime, DebugFreeCamRot, DeltaRot );
//Rot.Yaw = 0.0;
//Rot.Pitch = 0.0;
}
else
{
//super.UpdateRotation(DeltaTime);
//Rot.Yaw = 0.0;
//Rot.Pitch = 0.0;
}
}

Whoever is reading this will probably find faults, but this is how we did it (I had a mentor assisting me and he essentially altered this section). From what I'm collecting, he canceled out all inputs.

So save this file, I suggest you keep a backup of the previous copy somewhere.


Next we're going to the directory C:\UDK\UDK-2011-01\UDKGame\Config
Time to track down the file: DefaultInput.ini

Towards the bottom of the document, you will see 2 sections. Editor Bindings and Game Keyboard/Mouse Bindings.

Find the keys and commands under the Game/Keyboard change your coordination as you please. It should be pretty easily identifiable.

Make sure to incrementally save and reload UDK to test your scripts, if you compile after every short change, it makes it easier to identify where the code has issues. Best of luck, and if there are any questions, comments or critiques I'll do my best to reply and/or fix those issues. If you want to find out how to do something, I'd be more than happy to research and share the information as I come across it. Thanks guys, and good luck on your endeavors.


Finally, here's the final screenshot of this actually working. (Figure 1.3)

From Tutorial Files





3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Woops, accidentally deleted that last post.

    Like I was saying, good article for pointing people in the right direction. Can't argue with the results. (:

    Brian once he got this working? http://www.youtube.com/watch?v=WofqmWpXJZ8

    ReplyDelete