Difference between revisions of "HPL3/Amnesia: Rebirth/Tutorials/Ghouls"
m (formatting) |
(added to patrol tutorial (patrol mode + example)) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
== Scripting Setup == | == Scripting Setup == | ||
− | If the required map prerequisites are fulfilled, your | + | If the required map prerequisites are fulfilled, your Ghoul should be reactive to the player upon being activated via <code>Entity_SetActive()</code> in the map script. |
− | To give the | + | To give the Ghoul additional behavior, set up and switch the Ghoul into the appropriate mode and issue commands as desired. |
− | {{tip| More information on | + | {{tip| More information on Ghoul modes and commands can be found on the [[HPL3/Amnesia:_Rebirth/Scripting/Agents/Ghouls|Ghoul agent page]].}} |
+ | |||
+ | == Adding a patrol path == | ||
+ | |||
+ | First, make sure there are PathNodes or PathNodePatrol nodes in the enemy area. They can be added with the Area tool. | ||
+ | |||
+ | To make the ghoul patrol a set number of times, use the following code: | ||
+ | <syntaxhighlight lang="cpp"> | ||
+ | Ghoul_CommandPatrol_ClearNodes("ghoul"); //clear if ghoul already has nodes added | ||
+ | Ghoul_CommandPatrol_AddNode("ghoul", "PathNodePatrol_3", 3.0, 5.0); | ||
+ | Ghoul_CommandPatrol_AddNode("ghoul", "PathNodePatrol_7", 3.0, 5.0); | ||
+ | //Add more nodes as done above. | ||
+ | //Keep in mind the AI can find a straight path between nodes by itself, so you only need to add nodes at junctions and sharp turns | ||
+ | int HowManyTimesToLoop = 10; | ||
+ | Ghoul_CommandPatrol_Execute("ghoul", true, HowManyTimesToLoop, false, eGhoulSpeed_Walk, ""); //the parameters here can be changed of course | ||
+ | </syntaxhighlight> | ||
+ | {{warning| You can't start a patrol in OnEnter() or OnStart()! Use Setup() instead if you want the enemy to patrol when the map loads.}} | ||
+ | |||
+ | To make the ghoul patrol indefinitely, use the patrol mode functions instead: | ||
+ | <syntaxhighlight lang="cpp"> | ||
+ | Ghoul_ModePatrol_ClearNodes("ghoul"); | ||
+ | Ghoul_ModePatrol_AddNode("ghoul", "PathNodePatrol_3", 3.0, 5.0); | ||
+ | Ghoul_ModePatrol_AddNode("ghoul", "PathNodePatrol_7", 3.0, 5.0); | ||
+ | Ghoul_Mode_Set("ghoul", eGhoulMode_Patrol); | ||
+ | </syntaxhighlight> | ||
+ | {{tip| There are many other functions available to customize your ghoul behavior! If you haven't already, [[HPL3/Scripting/Scripting_Guide/Setting_up_CodeLite|set-up CodeLite]] to have easy access to all available functions.}} |
Latest revision as of 08:25, 15 November 2020
This tutorial will go over the basic setup required to use a Ghoul agent. This tutorial assumes you have basic mapping and scripting knowledge.
Map Setup
First, make sure any agents placed in your map are set to be inactive. This ensures that, when later activated in your map script, the agent is successfully added to AgentBlackboard.
The agent requires path nodes to move around, so make sure your map is populated with plenty of nodes. You can use the PathNodeGenerator area type to easily generate a large amount of nodes automatically (make sure whatever surfaces you want to generate nodes on are inside the area), but you may still want to place nodes manually in areas with difficult or precise navigation.
Scripting Setup
If the required map prerequisites are fulfilled, your Ghoul should be reactive to the player upon being activated via Entity_SetActive()
in the map script.
To give the Ghoul additional behavior, set up and switch the Ghoul into the appropriate mode and issue commands as desired.
Adding a patrol path
First, make sure there are PathNodes or PathNodePatrol nodes in the enemy area. They can be added with the Area tool.
To make the ghoul patrol a set number of times, use the following code:
Ghoul_CommandPatrol_ClearNodes("ghoul"); //clear if ghoul already has nodes added
Ghoul_CommandPatrol_AddNode("ghoul", "PathNodePatrol_3", 3.0, 5.0);
Ghoul_CommandPatrol_AddNode("ghoul", "PathNodePatrol_7", 3.0, 5.0);
//Add more nodes as done above.
//Keep in mind the AI can find a straight path between nodes by itself, so you only need to add nodes at junctions and sharp turns
int HowManyTimesToLoop = 10;
Ghoul_CommandPatrol_Execute("ghoul", true, HowManyTimesToLoop, false, eGhoulSpeed_Walk, ""); //the parameters here can be changed of course
To make the ghoul patrol indefinitely, use the patrol mode functions instead:
Ghoul_ModePatrol_ClearNodes("ghoul");
Ghoul_ModePatrol_AddNode("ghoul", "PathNodePatrol_3", 3.0, 5.0);
Ghoul_ModePatrol_AddNode("ghoul", "PathNodePatrol_7", 3.0, 5.0);
Ghoul_Mode_Set("ghoul", eGhoulMode_Patrol);