Difference between revisions of "Add character to scene"

From XStoryPlayer Wiki
Jump to: navigation, search
Line 116: Line 116:
 
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.
 
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.
 
</li>
 
</li>
 +
<li>Now give some feedback when you see the girl. Add this code to the player run.dat file:
 +
<syntaxhighlight lang="cpp">
 +
[START3]
 +
{
 +
[state.dyn.me.avatar.id == ALIEN &
 +
  state.dyn.me.avatar.range <= 10]
 +
{
 +
  feedback.s = "An alien girl?? Why is she looking so angry...";
 +
   
 +
  state.dyn.me.do.state2 = SEEN_ALIEN;
 +
}
 +
}
 +
</syntaxhighlight>
 +
Now after you see the alien girl you get this feedback.
 +
</li>
 +
<li>We want the alien girl to come to you after you say something.</li>
 
</ol>
 
</ol>

Revision as of 12:55, 13 January 2015

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.

Alien abduc1.jpg

Steps

  1. 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.
  2. Now we need a location that is the starting point for this character.
    Open the spaceship scene scene.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 copy waypoint2 and place it outside the cell like this:
    Maya waypoint1.jpg
  3. Open the /init/story/alien/init.dat file.
    In the pose settings you see that the scene_id = SPACESHIP1 and waypoint = "waypoint2".
    The pose contains all pose settings for this character. The character is derived from the object CHAR_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.
  4. Start the adbucted scene and if all went well, you should see an alien character outside your cell.
  5. 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 variables main_focus_type and main_def_exp do not only contain a value but can also be used to set the actual focus and expression.
    Set main_focus_type = STARE and main_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.
  6. Now we want the alien character to keep walking around in the spaceship. Add two more waypoints to the scene like this:
    Maya waypoint1.jpg
    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.
  7. 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.

  8. 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 <= 10]
     {
       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.

  9. We want the alien girl to come to you after you say something.