Characters

From Wolfire Games Wiki
(Difference between revisions)
Jump to: navigation, search
(PreDrawCameraNoCull function)
(PreDrawCamera function)
Line 439: Line 439:
 
[[#PreDrawCamera function|<code>PreDrawCamera</code>]] is called for characters in the scene that were not culled out of the view of this camera, in order to perform per-frame, per-camera functions. It is called for each character that didn't get culled immediately after the call to [[#PreDrawCameraNoCull function|<code>PreDrawCamera</code>]]. Unlike [[#PreDrawCameraNoCull function|<code>PreDrawCamera</code>]], this function is only called if the character is '''not''' culled by occlusion or frustum culling in this camera's view.
 
[[#PreDrawCamera function|<code>PreDrawCamera</code>]] is called for characters in the scene that were not culled out of the view of this camera, in order to perform per-frame, per-camera functions. It is called for each character that didn't get culled immediately after the call to [[#PreDrawCameraNoCull function|<code>PreDrawCamera</code>]]. Unlike [[#PreDrawCameraNoCull function|<code>PreDrawCamera</code>]], this function is only called if the character is '''not''' culled by occlusion or frustum culling in this camera's view.
  
'''Note''': [[#PreDrawCamera function|<code>PreDrawCamera</code>]] is called for each player character's camera, for cube map probes ("reflection captures"), for shadow cascades, etc. It may be called more than once per character per frame, since it handles per-camera actions. This is called after all calls to [[#PreDrawFrame function|<code>PreDrawFrame</code>]] have completed.
+
'''Note''': [[#PreDrawCamera function|<code>PreDrawCamera</code>]] is called for each player character's camera, for cube map probes ("reflection captures"), for shadow cascades, etc. It may be called more than once per character per frame, since it handles per-camera actions. This is called immediately after [[#PreDrawCameraNoCull function|<code>PreDrawCameraNoCull</code>]] was completed for the same object, with the same camera, so calls two these two functions get interleaved.
  
 
Examples of character-related things this function are useful (in the base scripts) include:
 
Examples of character-related things this function are useful (in the base scripts) include:

Revision as of 04:41, 2 December 2017


Contents

Overview

Characters are a game entities that are directly controllable by a player or by the AI.

Characters have Rigged Objects attached, which support skeletal animation, rag doll animation, blends of those two, and character physics.

TODO: More in depth description, akin to that in Hotspots and LevelScripts

Documentation

Callable functions and data available inside character scripts

A list of functions, data, etc, is created automatically whenever you run the game, in a file on your hard drive. This lists what external code you get "for free" and can call from inside a character script.

  • Windows: My Documents\Wolfire\Overgrowth\aschar_docs.h
  • Mac: ~/Library/Application Support/Overgrowth/aschar_docs.h
  • Linux: ~/.local/share/Overgrowth/aschar_docs.h

This documentation will change with each version of the game, so keep checking back on this aschar_docs.h file to see the most up to date information.

There are also wiki pages which have more detailed documentation many of these functions. These pages have a danger of going out of date, but give more detailed documentation on some of the code:

Character instances in other scripts

Characters are exposed to other scripts as instances of the MovementObject class.

MovementObject instances are like other objects in the game. They support everything that is supported by Object, and also have their own special set of functions, properties, etc.

If you have a handle to a [email protected] object in angelscript, you can convert it to an [email protected] by calling ReadObjectFromID(movement_object.GetID());.

Working with Characters in editor

TODO: How to set a character as playable in the editor.

TODO: List of supported character parameters and how to use them. Some of these things verge more into "game" territory and not "engine" territory, so should at the very least mention that it's fully changeable in script...

TODO: List of species specific traits? Some of these things verge more into "game" territory and not "engine" territory, so should at the very least mention that it's fully changeable in script...

How to create a character

Character XML files

TODO: Description of XML format

File path conventions

TODO: Description of where to add files in mods so they don't conflict. Ala Hotspots#File_path_conventions

Modeling

TODO: Links to or docs on modeling, graphics features like fur fins, various texture channels and what their components (alpha etc) mean, UVs, object space normals, etc. Also, any export info that would be necessary.

Rigging

TODO: Links to or docs on rigging and rig export

Hull

TODO: Links to or docs on character hulls

Animations

TODO: Links to or docs on animations and export, tagging, etc

Morph targets

TODO: Links to or docs on morph target animations for hands, face, etc

Eyes

TODO: Links to or docs on morph target animations for eyes (might roll this up into other sections/other pages?)

Attacks

TODO: Links to or docs on attacks system and export, tagging, etc - related partly to animations.

TODO: Possibly also scripting attacks and animations, and character-bound input, etc - though maybe that should be in a different section?

How to add a character to the spawner menu

Short version:

  • You must add it in a mod.
  • You can add as many characters to the spawner menu as you want in a single mod, you just need to follow the below instructions for each, and add multiple <Item> tags to your mod.xml file.

In your mod.xml file, add this xml tag: (TODO: Make these paths more specific to characters)

<Item category="My Custom Mod Characters"
      title="Some Character To Spawn"
      path="Data/Objects/example_item_pack/mod_item_example.xml"
      thumbnail="Data/UI/example_item_pack/thumbs/mod_item_example.png" />
  • category is the top level category where the character will show up, in the Load menu.
  • title is the name of the character, as it will show up in the spawner menu.
  • path is the path to the character XML that will get spawned. See the How to create a character section for which XML file to target (either the character XML itself, or a version you saved off that has modified default parameters). TODO: Be careful to advise which character XML to add to the spawner - there are multiple character XML files!
  • thumbnail is the image that will be used for a tooltip when you hover over your character in the spawner menu.

See GameInstallDir/Data/ExampleMods/mod_xml_specification.txt for full information.

Character script hook functions

These functions are required. If you override the character controller script for a character in your mod, you must include all of these functions:

These functions are optional. These functions do not have to be added to your overridden character controller script, but will be called if they are present:

Init function

bool Init(string character_path) { return true; }

Required

Init is called when the character is first to be loaded, upon level load.

Must return true upon success, and false upon failure.

Important things to do in this call are to set the motion object character path, load the character (character_getter.Load(character_path);), read the species tag (character_getter.GetTag("species")), set up the skeleton, etc.

Be careful, this may be called before some objects or script params are present in the level.

Reset function

void Reset() { }

Required

TODO: How much of this is correct?

Reset is called whenever the level is reset. This does not happen when a level is first loaded, or when undo/redo are fired in the editor.

This happens when the player hits the "L" debug key to manually reset the level.

This also happens upon player respawn (but this is up to the level script, and modded level scripts might not do that).

When Reset gets called for a character:

  1. Reset(); is called
  2. Physics for the character is set up
  3. Global variables in the AS context are reset
  4. SetParameters(); is called
  5. PostReset(); is called
  6. Item attachements are done, and attachment callbacks are called ([1], [2], [3])

SetParameters function

void SetParameters() { }

Required

SetParameters is called when the character is first loaded, whenever the script parameter values are changed via the GUI, and whenever Reset() is called.

It is also called when an undo/redo is fired in the editor, to reload script params from that point in history.

This function allows the character script to work with script parameter values. You can use it to define, change, verify, protect (undo writes), or locally cache script parameter values.

You can also use this to work with game objects that you use character script params to control (if any - this is a trick usually done in hotspot scripts, with placeholder objects, but there isn't any reason why a character script couldn't do similar things, if it was somehow valuable).

PostReset function

void PostReset() { }

Required

TODO: How much of this is correct?

PostReset is called whenever the level is reset. This does not happen when a level is first loaded, or when undo/redo are fired in the editor.

This happens when the player hits the "L" debug key to manually reset the level.

This also happens upon player respawn (but this is up to the level script, and modded level scripts might not do that).

When Reset gets called for a character:

  1. Reset(); is called
  2. Physics for the character is set up
  3. Global variables in the AS context are reset
  4. SetParameters(); is called
  5. PostReset(); is called
  6. Item attachements are done, and attachment callbacks are called ([1], [2], [3])

ScriptSwap function

void ScriptSwap() { }

Required

ScriptSwap is called before Update(), when the character control script gets swapped (caused by going from player control to AI control, or vice-versa).

This function gives the script an opportunity to properly adjust its variables after the transition to the new script, so updates happen smoothly. Existing global variables are copied over, but variables that aren't shared between the scripts might need to be derived and/or initialized in this function.

Note: The character model, rigged object, etc, stay loaded when this script is swapped, so this is mostly just available to handle special on-swap behavior (if you want to add any).

Note: The update frequency is based on whether the new script is a player control script (Data/Scripts/playercontrol.as, set to update 120-per-second) or an AI control script (any other script, set to update 30-per-second, with a random offset with 120hz frequency to spread out the updates).

When the script gets swapped:

  1. The global variables are saved from the old script
  2. The new script is loaded
  3. The global variables are restored to the new script
  4. The update frequency gets selected, based on which script got loaded
  5. this function is called

Update function

void Update(int num_frames) { }

Required

Update is called regularly by the engine so you can perform work. It is only called while the game is unpaused.

It may be useful to do initialization once in this function, if you need objects or character script params to be present.

Be careful to keep this function short, sweet, and fast. Update gets called 120 times a second as of the time of this writing.

Note: The update frequency is based on whether this script is a player control script (Data/Scripts/playercontrol.as, set to update 120-per-second) or an AI control script (any other script, set to update 30-per-second, with a random offset with 120hz frequency to spread out the updates).

UpdatePaused function

void UpdatePaused() { }

Required

UpdatePaused is called regularly by the engine while the game is paused so you can handle camera movements. It is only called for characters that are controlled by players.

While the game is paused, Update does not get called, and this function does.

Be careful to keep this function short, sweet, and fast. UpdatePaused gets called 120 times a second as of the time of this writing.

ReceiveMessage function

void ReceiveMessage(string message) { }

Required

ReceiveMessage is called when messages have been sent to this character by the engine, level, or objects in levels.

Objects in levels (such as hotspots or other characters) can send this using movement_object.SendMessage("some message string");.

Parameters can be sent by separating them with spaces, and putting quotes around parameters that might contain spaces, then using the TokenIterator object. TODO: Write a TokenIterator example and link to it.

Note: If you're setting up the code to send a message to a character, you might want to choose to only send messages to player characters, or non-player characters. TODO: Example of how to do this filtering.

SetEnabled function

void SetEnabled(bool is_enabled) { }

Required

The SetEnabled hook function is called when movement_object.SetEnabled(bool); gets called on the character by another script.

This function allows the character to enable or disable any objects that should be associated with the character (such as fire ribbons, sounds, shadow objects, character camera item flashes, and water splashes).

This function can also be used to internally set variables so that its functions have no effect. The engine will generally not call the character if it is not enabled (except when it gets re-enabled), but other scripts could theoretically call functions on the character using movement_object_instance.Execute("some code");.

Note: It may be viable to call Dispose() from inside this function, as long as you're careful not to double-delete things.

MovementObjectDeleted function

void MovementObjectDeleted(int character_id) { }

Required

Callback to notify a character script that a different character got deleted, in case it was tracking that character and needs to stop tracking it.

AttachWeapon function

void AttachWeapon(int weapon_item_id) { }

Required

Called when the player picks up a weapon item off the ground. (TODO: Is this correct? Verify by editing the script to add debug logging and run through the scenario. Maybe also check engine code?)

AttachMisc function

void AttachMisc(int misc_item_id) { }

Required

Called when the player picks up a miscelaneous (non-weapon) item off the ground. (TODO: an example? Might be vestigial, but still required?)

HandleEditorAttachment function

void HandleEditorAttachment(int item_id, int attachment_type, bool is_mirrored) { }

Required

Called when the player attaches an item to a character in the editor.

attachment_type is a value from the AttachmentType enum. TODO: Link to the docs for that enum.

NotifyItemDetach function

void NotifyItemDetach(int item_id) { }

Required

Called when the player drops an item or weapon, or detaches it in the editor. TODO: Verify that this is all correct.

GetTempHealth function

float GetTempHealth() { return 1.0f; }

Required

Get the current health of the character (called "temp health" to distinguish from the character's current max health)

ForceApplied function

void ForceApplied(vec3 force) { }

Required

NOTE: Vestigial function that is not called by the engine, but still required to be present. It could be called by another script, if so desired (via movement_object.ApplyForce(vec3);), but the base game doesn't currently do this. RiggedObject functions are used instead for this purpose, or other collision response callbacks that are more specialized (like HitByItem).

Contact function

void Contact() { }

Required

Called when any collision happens, including debouncing/resting collisions (which are filtered out and don't trigger other collision callbacks, such as Collided(...))

Collided function

void Collided(float posx, float posy, float posz, float impulse, float hardness) { }

Required

Called when a collision just happened that is stronger than a very light tap (light and resting collisions will be filtered out by this, but won't be by Contact()

AboutToBeHitByItem function

int AboutToBeHitByItem(int item_id) { return 1; }

Required

Called when a character is about to be hit by an item so deflection can be tested/triggered.

Return -1 to specify that the collision was avoided (such as when the character deflects or catches the item). Make sure to handle the result of that avoidance as well inside this function, such as flinging the weapon to the side, or attaching it to the character's hand.

Return 1 to specify that the collision could not be avoided, and the collision handling should continue on. Handle the reactions to this case in the HitByItem() callback, instead of in this function.

HitByItem function

void HitByItem(string material, vec3 point_of_impact, int item_id, int impact_type) { }

Required

Called when the character is hit by an item so it can react to the impact, take damage, etc.

  • material: Per-polygon-edge material description for the edge that hit the character, in case the result of impact should be different (less or more damage, sharp vs not sharp, etc). Note that the base game doesn't do anything in response to this value.
  • point_of_impact: The point where the item impacted the character
  • item_id: The id of the game object that hit this character
  • impact_type: 2 = sticks, 1 = cut, 0 = bounce off

Note: Any avoidance of the collision (catching the item, deflecting it, etc) should happen in AboutToBeHitByItem(int) instead.

WasHit function

int WasHit(string type, string attack_path, vec3 dir, vec3 pos, int attacker_id, float attack_damage_mult, float attack_knockback_mult) { return 1; }

Required

Handles what happens if a character was hit. Includes blocking enemies' attacks, hit reactions, taking damage, going ragdoll and applying forces to ragdoll.

  • type: A string that identifies the action and thus the reaction
  • attack_path: A path to the attack XML file for this attack
  • dir: The vector from the attacker to the defender
  • pos: The impact position
  • attacker_id: The game object Id of the character who is attacking
  • attack_damage_mult: The attack damage multiplier for the attack (specified in the base scripts in the attacking character's Attack Damage script param)
  • attack_knockback_mult: The attack damage multiplier for the attack (specified in the base scripts in the attacking character's Attack Knockback script param)

Return values: (TODO: Verify that the whole two-pass thing here is accurate. This could just be a convention used by the scripts, and not values that are important to the engine itself)

  • 0: miss - Return if the attack was a complete wiff, and did not land at all (dodged, ducked under, light attacks blocked with a knife, etc)
  • 1: going to block - Return if the block attempt was successfully executed (on the first pass of the attack)
  • 2: hit - Return if the attack landed, and was not countered (on the second pass of the attack)
  • 3: block impact - Return if the attack landed, but was blocked (on the second pass of the attack)
  • 4: invalid - Returned in the base scripts if type or attack_path have unexpected/unhandled values
  • 5: going to dodge - Return if the dodge attempt was successfully executed (on the first pass of the attack)

HandleCollisionsBetweenTwoCharacters function

void HandleCollisionsBetweenTwoCharacters([email protected] other_character) { }

Required

Called when the game detects two characters have collided, so physics response impulses and possibly additional gameplay logic can be applied.

PreDrawCamera function

void PreDrawCamera(float curr_game_time) { }

Required

PreDrawCamera is called for characters in the scene that were not culled out of the view of this camera, in order to perform per-frame, per-camera functions. It is called for each character that didn't get culled immediately after the call to PreDrawCamera. Unlike PreDrawCamera, this function is only called if the character is not culled by occlusion or frustum culling in this camera's view.

Note: PreDrawCamera is called for each player character's camera, for cube map probes ("reflection captures"), for shadow cascades, etc. It may be called more than once per character per frame, since it handles per-camera actions. This is called immediately after PreDrawCameraNoCull was completed for the same object, with the same camera, so calls two these two functions get interleaved.

Examples of character-related things this function are useful (in the base scripts) include:

  • Updating shadow placement and character fire effects
  • Updating per-character UI elements (such as the debug health bar, stealth debug, per-character dialogue editor UI, item-to-character lines, etc)

PreDrawCameraNoCull function

void PreDrawCameraNoCull(float curr_game_time) { }

Required

PreDrawCameraNoCull is called for all objects in the scene, to perform per-frame, per-camera functions. Unliked PreDrawCamera, this function is always called, even if the object is culled by occlusion or frustum culling for this camera.

Note: PreDrawCameraNoCull is called for each player character's camera, for cube map probes ("reflection captures"), for shadow cascades, etc. This is called after all calls to PreDrawFrame have completed.

Examples of character-related things this function are useful (in the base scripts) include:

  • Doing character animation discontinuity fixes
  • Updating the camera full-screen vignette effects for the character's camera
  • Setting camera depth-of field for the character's camera

PreDrawFrame function

void PreDrawFrame(float curr_game_time) { }

Required

PreDrawFrame is called to let scripts perform per-frame calculations before anything in the frame is drawn, like updating the character's blob shadows.

Note: After PreDrawFrame is called for this character, then all objects attached to this character are moved to their correct positions.

Note: Once all objects have had PreDrawFrame called on them, then the rest of the rendering is done for the frame.

DisplayMatrixUpdate function

void DisplayMatrixUpdate() { }

Required

Callback to handle time-based procedural skeletal animation effects that aren't animation controlled (in the base scripts, just breathing right now)

Note: This function gets triggered at the RiggedObject level, not at the MovementObject level.

FinalAnimationMatrixUpdate function

void FinalAnimationMatrixUpdate(int num_frames) { }

Required

Callback to do character IK calculations

For the base unmodified game scripts, examples include rolling contact with ground and rolling animation transitions, turning torso towards target, planting feet on ground, ledge hanging, tethering when dragging bodies, eye look direction, foot balancing on "balance" collision painted surfaces. It is also called by base game in "FixDiscontinuity"

Note: This function gets triggered at the RiggedObject level, not at the MovementObject level.

FinalAttachedItemUpdate function

void FinalAttachedItemUpdate(int num_frames) { }

Required

Note: This function gets triggered at the RiggedObject level, not at the MovementObject level.

TODO: What is this for? Weapon IK? It seems to be empty in the base game scripts right now, except it has some temporary testing code for doing some sword stab IK that affects the weapon?

HandleAnimationEvent function

void HandleAnimationEvent(string event, vec3 world_pos) { }

Required

Animation events are created by the animation files themselves. For example, when the run animation is played, it calls HandleAnimationEvent("leftrunstep", left_foot_pos) when the left foot hits the ground.

Note: This function gets triggered at the RiggedObject level, not at the MovementObject level.

TODO: List current animation events that are tagged in scripts? Is this system open for adding new items, and do any existing ones require behavior to be implemented, or could they be ignored?

WasBlocked function

void WasBlocked() { } 

Required

Vestigial function not called by the engine or base game scripts. It is exposed to other scripts on the [email protected] interface, and must be present if it gets called by game scripts.

TODO: More details on what to use instead? Does WasHit(...) handle everything this function would handle?

Dispose function

void Dispose() { }

Optional

Dispose is called when the character is destroyed, either by manually deleting it, or when the level is unloaded.

WARNING: Do not DeleteObjectID for other game objects from this function! If you try to, then the game will likely crash on level unload when calling Dispose() on the object you deleted. Also don't try to QueueDeleteObjectID() through Dispose, or it will really mess with undo/redo state.

This function allows the character to free any non-game objects that are owned by this character (such as fire ribbons, sounds, shadow objects, character camera item flashes, and water splashes).

ResetWaypointTarget function

void ResetWaypointTarget() { }

Optional

ResetWaypointTarget is called when a character or path point that this character is directed to follow (connected to) is changed.

This happens when the target gets deleted, this character is disconnected from it, or the connection target is updated to a new target. This can happen either through the editor, or through scripting logic.

Personal tools