0% found this document useful (0 votes)
2 views

Edit_tutorial5

This document provides a tutorial on adding computer-controlled enemies in a 3D game using Reality Factory. It outlines the steps to register characters, create scripts for their behavior, and implement movement and patrolling functionality. Key components include editing configuration files, utilizing script points for navigation, and defining movement commands within the game's scripting environment.

Uploaded by

rkrams1989
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Edit_tutorial5

This document provides a tutorial on adding computer-controlled enemies in a 3D game using Reality Factory. It outlines the steps to register characters, create scripts for their behavior, and implement movement and patrolling functionality. Key components include editing configuration files, utilizing script points for navigation, and defining movement commands within the game's scripting environment.

Uploaded by

rkrams1989
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

World Editing 5

Introduction to 3D Game Development

Game Development using RF


Tutorial 5
Adding Enemies

In this section, we will learn how to add computer controlled characters with
prescribed behavior to your game.

The addition of enemies (computer controlled AI in-game character) is performed in


the following way:

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

The parameters above are all self explanatory.


2. Now you may add any number of the newly added pawn to your level!

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

5.1 Make it move!


Movement of monsters is easy in RF – you need to specify where the monster should
move and then make it move inside your own script file.
First we need to specify where to move. The destination is being specified by a path
point called ScriptPoint in RF. ScriptPoint can be added in RF through the entity
template.

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

Fig. Rotating the ScriptPoint entity

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

The edited script file content is as follow:


{
start[ ()
{
Console(true);
PlayAnimation("idle", true, "");
Delay("idle", 3, "");
RotateMoveToPoint("walk", 100, 20, true, "footsteps\\m1.wav");
MoveToPoint("walk", 50, "footsteps\\m1.wav");
} ]
}
Note I add the call Console(true); statement. This will show on the run time screen
what kind of action the pawn is doing (to help debugging). The Delay call is just a
delay loop to let you see more clearly the transition of scripting statements. In actual
situation it can be used to make more accurate timing or for any effect you can think
of.

Now compile and run the level to see the pawn in action!

5.2 Make it patrol


Patrolling of monsters is a common behavior inside a game. To make the monster to
walk its beat is relatively easy in RF.
First we need to specify the patrolling path. The path is being specified by a number
of ScriptPoints in RF.

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.

Finally edit the script file to add a patrol call:


{
start[ ()
{
Console(true);
PlayAnimation("Idle", true, "");
Delay("Idle", 3, "");
RotateMoveToPoint("walk", 100, 20, true, "footsteps\\m1.wav");
MoveToPoint("walk", 50, "footsteps\\m1.wav");
NewOrder("Patrol");
}]
Patrol [ ()
{
NextPoint();
RotateMoveToPoint("walk", 100, 20, true, "footsteps\\m1.wav");

5
World Editing 5
Introduction to 3D Game Development

MoveToPoint("walk", 100, "footsteps\\m1.wav");


RestartOrder();
} ]
}

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.

You might also like