Add character to scene
From XStoryPlayer Wiki
In this tutorial we will add a female alien character to the scene. We will let her walk by the cell once in a while.
If you try to talk with her, she gets angry and says you should be quiet.
Steps
- Copy the files from the 'Tutorial resource pack' for this tutorial to the appropriate directories.
We will describe these files here briefly:
-
/init/story/alien
: This is the brain for the alien character. Just like the player each character has a brain. -
/scenes/capture
: These are the motion capture files used for the alien character. -
/scenes/character6
: These are the character and cloth meshes. -
/scenes/charobj
: These meshes are used for collision detection for characters in general. -
/scenes/sounds
: These files are the sound files used for the character. -
/scene/textures
: These files are the texture files used for the character.
-
- Now we need a location that is the starting point for this character.
Open the spaceship scenescene.ma
and create a duplicate instance of the waypoint object.
A duplicate instance copies only the instance of the object not the mesh itself. Name the copywaypoint2
and place it outside the cell like this:
- Open the
/init/story/alien/init.dat
file.
In the pose settings you see that thescene_id = SPACESHIP1
andwaypoint = "waypoint2"
.
The pose contains all pose settings for this character. The character is derived from the objectCHAR_BASE
, you can find more pose settings in the file:
/init/std/base/char/char_base.dat
. You see that the scene_id and waypoint are overridden. - Start the adbucted scene and if all went well, you should see an alien character outside your cell.
- Now lets make her look at you and change her expression. Open the
/init/story/alien/brain/dyn.dat
file. This file contains the dynamic state for the brain.
Here you can add brain state variables that can be changed during the game. They are automatically saved when you save the game.
The variablesmain_focus_type
andmain_def_exp
do not only contain a value but can also be used to set the actual focus and expression.
Setmain_focus_type = STARE
andmain_def_exp = A_BIT_ANGRY
. This will make the character stare and you with an somewhat angry expression.
Run XStoryPlayer and you should see that she follows you with an somewhat angry expression. - Now we want the alien character to keep walking around in the spaceship. Add two more waypoints to the scene like this:
Name them waypoint3 and waypoint4. Set the starting waypoint in the pose settings of the alien to waypoint3.
Now start XStoryPlayer again. Press F6 to go into free view mode. "Fly" around the wall and you should see the alien behind it now. - Now we will add some walking scripting. Walk planning is automatically calculated based on the the collision objects in the scene.
So we only have to redirect the character using the script and she walks by herself.
Open the/init/story/alien/brain/run.dat
file. It contains the code that is run for each brain.
Replace the code with this:#include "init/std/base/char/brain/code/run.dat" //------------------------------------------- <*state_run> res = true; case (state.dyn.me.do.state) { [RUN0] state_run0(); } </state_run> //------------------------------------------- <state_run0> case (state.dyn.me.do.state2) { [NONE] { // Set timer to 20 seconds do_set_timer(20); state.dyn.me.do.state2 = START; } [START] { // Wait for timer loc.ts = GetTs(); [loc.ts < state.dyn.me.do.ts] return; state.dyn.me.do.state2 = WALK1; } [WALK1] { // If busy with pose then wait [state.dyn.me.pose.result == NONE] return; // Walk towards waypoint4 and stand there // No need to end exactly on this waypoint loc.state.pose_type = STAND; loc.state.waypoint = "waypoint4"; loc.state.exact = 0; SetPose(loc.state); state.dyn.me.do.state2 = WALK2; } [WALK2] { // If busy with pose then wait [state.dyn.me.pose.result == NONE] return; // Walk towards waypoint3 and stand there // No need to end exactly on this waypoint loc.state.pose_type = STAND; loc.state.waypoint = "waypoint3"; loc.state.exact = 0; SetPose(loc.state); state.dyn.me.do.state2 = WALK1; } } </state_run0>
This code will make the character walk between the two waypoints continuously.
Start XStoryPlayer and after the player has gotten the feedback "Wait, I believe I hear someone coming...", you should see the alien girl walking by. - Now give some feedback when you see the girl. Add this code to the player run.dat file:
[START3] { [state.dyn.me.avatar.id == ALIEN & state.dyn.me.avatar.range <= 6] { feedback.s = "An alien girl?? Why is she looking so angry..."; state.dyn.me.do.state2 = SEEN_ALIEN; } }
Now after you see the alien girl you get this feedback.
- We want the alien girl to come to you after you say something. The ref.dat file for the alien character can be used for this.
Open it and change the
ref.state.run0
code to this:run0 { hello.greet = { talk.s = "Be quiet prisoner!"; } get.get = hello.greet; if.get = hello.greet; when.get = hello.greet; where.get = hello.greet; why.get = hello.greet; set.get = hello.greet; info.get = hello.greet; word.get = hello.greet; }
When the character is in the RUN0 state it will receive talk events. We can use the
ref.state.run0
code variables to react on these talk events.
Using the above code we basically react to any talk event and let the alien reply that you should be quiet.