Rich Zap
Right so after several years of using this place i finally get round to putting something back. Im currently a member of a barely known mod team called Anomalous Mods, we are currently producing the Third Contingent mod (http://3c.moddb.com). But i am also working on several other projects...
Although i am now a relatively skilled coder i did find it hard to learn Uscript at first through the wikis tutorials. It wasnt until i found Tuco's tutorial page (http://www.student.oulu.fi/~tkorva/ut2004devtips.html) that i was able to really start doing stuff with Uscript that wasnt merely changing values within existing code or making minor changes. So im going to put down some steps to making a reasonably simple custom actor that should give some returns to anyone who is learning while simultaneously been easy to understand.
Eagle-Bee Actor Part One
Before You Start
As with the UnrealScript Hello World tutorial we need to create a directory to hold our mutator code. The name of the directory determines the name of the package into which your code will be compiled. To that end you need to Set Up Package Folders:
- Create a directory
EagleBeeActor
within your UT2004 directory - Create a directory
Classes
within theEagleBeeActor
you just created.
You should have the following folder tree:
UT2004 +- EagleBeeActor +- Classes
Aims
The aim of this tutorial will be to take the basic Actor code from which most classes in UT2004 are extended and create an actor which will follow players around a map. We will simply be using the Eagle head icon which is default so that the code is self contained within one class however the code could easily be modified to include a static mesh or a different icon.
Introduction
So lets get started, first off theres an important resource that you need to be aware of if you arent already... http://unreal.student.utwente.nl/ contains source code for all unreal games sorted so that functions and classes are easy to locate and use. UScript development is much more difficult without this resource. One page of particular importance for this tutorial is the actor page (http://unreal.student.utwente.nl/uncodex-ut2004/engine/actor.html.gz) which conatins a list of functions and variables which Actor provides.
For now were going to keep the actor very simple, we will build more complexity in later. So this is the first code we need to get down, most of it is simply settings which we will need in order to develop the actor further:
Getting the actor moving
//------------------------------------------------------------- // Eagle-Bee Actor - Designed to follow the player around a map //------------------------------------------------------------- Class EagleBeeActor extends Actor Placeable; //The placeable comment means that our actor can be placed in a map within Ued. Function PostBeginPlay() { Super.PostBeginPlay(); Velocity.z = 100; //Sets our actor to move at a steady speed of 100 upwards } DefaultProperties { bHidden=false //Allows the actor to be seen. DrawType=DT_Sprite //Sets our actor to use sprite drawtype, as no sprite has been specified it will use //the default Eagle Head image. RemoteRole=ROLE_None //Networking, we wont worry about this till later so for now we will just leave it as None. bUseCylinderCollision=true //Sets the collision on our actor to be an invisible cylinder of height 30UU by radius 30UU. CollisionHeight=30.0 CollisionRadius=30.0 bCollideActors=True //Collision Properties, basically tells our actor to collide with everything. bBlockActors=True bBlockKarma=True bBlockNonZeroExtentTraces=True bBlockZeroExtentTraces=True bCollideWorld=True bStatic=False //Allows our actor to move. bStasis=False Physics=PHYS_Flying //Tells our actor to use 'Flying' physics where velocity, acceleration etc... are applied. }
Movement of actor |
So now that youve coded and compiled this we need to test it. Run UT2004 and start an Instant Action DeathMatch game, make the bot count zero so they dont interfere while you're testing. Once playing type in the console Summon EagleBeeActor.EagleBeeActor, our new actor should appear and start floating gently upwards. Unfortunately it will float straight out of the level and die because although we have instructed it that it can collide with everything, we havent told it what to do when it does collide. |
Adding Collision Effect
Now obviously at the moment the actor is pretty dull as it will just float up and die, we need to make it a bit more interesting so thats what were going to do now. We are going to add a simple function which will tell our actor to bounce off of objects. The function given below should be added into the code without modification to anything else. All collisions that occur will be perfectly elastic in other words if you are travelling at a speed of 5 MpH when you hit an object, you will bounce off at 5 MpH as well. Understanding the maths involved is not within the scope of this tutorial, however you may want a look at the Vector page if you want to learn them or just refresh yourself on their workings. it is enough for now simply to know that this will simply cause the velocity to change so that it makes the object rebound off anything it collides with. Function Hitwall(vector HitNormal, actor Wall) { //If the actor collides with anything, rebound. Velocity = (Velocity - 2.0*HitNormal*(Velocity dot HitNormal)); } Now you've added that code in, recompile and test out the same way as you did before (summon EagleBeeActor.EagleBeeActor). HitWall is a native function which is called whenever the actor collides with anything that it is set to collide with. |