Edit_tutorial5
Edit_tutorial5
In this section, we will learn how to add computer controlled characters with
prescribed behavior to your game.
0. You need to have already built an actor (character) and placed the actor file
(with extension .act) into the “RealityFactory\media\actors” directory.
Alternatively, you can choose an actor from among the files available inside
that directory. For this example, we would use the robot actor, which is
already placed inside the ‘pawn’ subdirectory of actors under the name
“robot.act’.
1. Prepare a script file and placed it inside the “RealityFactory\scripts” directory.
In Reality Factory, those computer controlled characters are collectively called
‘pawn’. In order to let the Reality Factory system knows your added
characters, you have to registering them by editing the “pawn.ini” file inside
the “RealityFactory\install” directory. Following is the content of the
“pawn.ini” file which registered your own character “Virgil” and your enemy
“robot”:
[Virgil]
actorname = Virgil_red.act
actorrotation = -90 180 0
actorscale = 1
fillcolor = 255 255 255
ambientcolor = 255 255 255
subjecttogravity = true
boundingboxanimation = Idle
shadowsize = 30
[robot]
actorname = robot.act
actorrotation = 0 90 0
actorscale = 1.4
fillcolor = 255 255 255
ambientcolor = 255 255 255
subjecttogravity = true
boundingboxanimation = idle
Start the RF editor and build a simple level with the necessary information (please
refer to materials in previous RF sections).
1
World Editing 5
Introduction to 3D Game Development
Let’s add the enemy to our level. Choose the template mode and scroll down the list
and choose “Pawn” entity. Add this to your level and place it at some appropriate
position, for example, just in front of the player.
Start the entity editor and choose the “pawn” entry you have just added. Change the
entries of the pawn into the following:
i.e. you only need to change the Pawn type to “robot”, which is the type you’d
registered in the pawn.ini file in step 2. Also you have to add script file “enemy1.s” to
instruct the RF runtime to load the script file that we have just written.
The scripts in Rf is stored inside a file with suggested extension ‘.s’. So we will first
created a text file called ‘enemy1.s’ and placed it inside the ‘scripts’ subdirectory of
installed RF directory.
In RF, all the scripts inside a script file must be placed within a set of braces ‘{‘ & ‘}’
and each script file consists of collections of functions called ‘orders’. An order is
designated by a pair of brackets ‘[‘ & ‘]’ with a C function like body in it. For
example, the scripts below illustrate a pawn with an order called ‘start’.
{
start[ ()
{
PlayAnimation("idle", true, "");
RestartOrder();
} ]
}
Now compile and walkthrough the level, you should be able to see the following
screen which show our newly added friend.
2
World Editing 5
Introduction to 3D Game Development
Add a ScriptPoint and place it somewhere inside the level. The placement of
ScriptPoint need not be exactly at the place you place the pawn because you can
control the pawn to move to the ScriptPoint. A little hint is that the orientation of the
ScriptPoint should not deviate too much from the stating point (you can also make it
happen by adjusting the rotation speed of the pawn). To change the orientation of an
entity, select the entity and press the Move/Rotate button, then drag with right mouse
button pressed. Also the height of a script point for a pawn should be set at
approximately the ground level to avoid strange orientation of the pawn when moving.
3
World Editing 5
Introduction to 3D Game Development
Now give a name to the entity by adding it to the szEntityName entry inside entity
editor as shown
Now select the pawn entity and set its SpawnPoint entry to the name of our added
script point i.e. patrolpt1. Also you need to specify the SpawnOrder in this case. The
edited entity should like this:
Finally in order to make the pawn move, we use the following functions:
RotateMoveToPoint(Animation, Rotation Speed, Speed, State, Sound);
The above function will rotate the pawn to face the ScriptPoint and move towards it at
the same time. First parameter is the motion we choose pawn to perform. The second
speed is the translational speed. The State parameter determine whether rotation about
X axis be performed (at some instance where we want to twist of orientations).
After the alignment is being performed, the pawn can walk straight to the ScriptPoint
by the following function:
MoveToPoint(Animation, Speed, Sound);
4
World Editing 5
Introduction to 3D Game Development
Now compile and run the level to see the pawn in action!
Add the second patrol point called patrolpt2 to the level and edit its content so that the
resulting ScriptPoint forms a circular ring. The monster thus will walking circularly
among these points. The simplest case is 2 points: Set the NextPoint entry of patrolpt1
to patrolpt2 and NextPoint entry of patrolpt2 to patrolpt1.
5
World Editing 5
Introduction to 3D Game Development
Hints:
1. The pawn will “try” to walk according to your instructions, thus the placement of
script point is critical. You should place the script point close to the ground so that
the actor can reach it. Don’t place it in the air as the “robot” pawn can’t fly in our
setting.
2. The pawn is designed to have some bounding volume (box) to enable easy
calculation for collision. As the bounding box is the greatest encapsulation, the
actor will thus occupy quite a large volume in the level, making it difficult or
impossible to rotate in some small space e.g. corner. In such cases, the actor will
cease moving. Also the actor rotation velocity will determine whether it will reach
a particular script point or not. Thus you may also need to change the orientation
of the script point to make it patrol in the above experiment.