Npc dog/Playing fetch with Dog: Difference between revisions
No edit summary |
m (Setting bug notice hidetested=1 param on page where the bug might not need tested in param specified) |
||
(13 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
==Overview== | |||
[[Dog|D0G]]'s [[AI]] is largely dedicated to picking up physics objects and playing fetch with a target (usually, the player). | [[Dog|D0G]]'s [[AI]] is largely dedicated to picking up physics objects and playing fetch with a target (usually, the player). | ||
As shown in {{hl2|1.bold}}, D0G can grab objects with his built-in [[Gravity Gun]], toss them over an arcing trajectory, wait for it to thrown back at him, and either repeat that cycle, or search a new object dynamically. | As shown in {{hl2|1.bold}}, D0G can grab objects with his built-in [[Gravity Gun]], toss them over an arcing trajectory, wait for it to be thrown back at him, and either repeat that cycle, or search for a new object dynamically. | ||
[[File:d1_eli_02_dog_scripting.jpg|thumb|right|Valve went all-in with their scripting...]] | [[File:d1_eli_02_dog_scripting.jpg|thumb|right|Valve went all-in with their scripting...]] | ||
[[File:dog_fetch_scripting.jpg|thumb|right|... but you don't have to.<br>(''prop'' is the TV. <code>SetThrowTarget</code> isn't necessary to play with the player; included for completeness) | [[File:dog_fetch_scripting.jpg|thumb|right|... but you don't have to.<br>(''prop'' is the TV. <code>SetThrowTarget</code> isn't necessary to play with the player; included for completeness).]] | ||
While the logics setup used in Eli's junkyard ({{code|d1_eli_02}}) might seem frighteningly complex, a large portion of it has to do with spawning new crates dynamically, and tracking their fate (enabling D0G to act disappointed or excited), and then switching to play with his deactivated [[npc_rollermine|Rollermine]]. As well as a handful of scripts related to [[Alyx]]. | While the logics setup used in Eli's junkyard ({{code|d1_eli_02}}) might seem frighteningly complex, a large portion of it has to do with spawning new crates dynamically, and tracking their fate (enabling D0G to act disappointed or excited), and then switching to play with his deactivated [[npc_rollermine|Rollermine]]. As well as a handful of scripts related to [[Alyx]]. | ||
__TOC__ | |||
==Scripting== | |||
The actual setup to play fetch with D0G is not that complicated: | The actual setup to play fetch with D0G is not that complicated: | ||
* Use [[npc_dog]] in his most basic 'configuration', that is - not distracted by combat, [[scripted sequence]]s, or [[ai_goal_follow|follow]] behavior; all of them usually make his AI switch away from the | * Use [[npc_dog]] in his most basic 'configuration', that is - not distracted by combat, [[scripted sequence]]s, or [[ai_goal_follow|follow]] behavior; all of them usually make his AI switch away from the catch-and-throw game. | ||
* Have prop physics available to him. | * Have prop physics available to him. | ||
* Now use the following [[Inputs]] to make him play fetch: | * Now use the following [[npc_dog#Inputs|Inputs]] to make him play fetch: | ||
*# < | *# <b>SetThrowTarget</b> <nowiki><</nowiki>[[targetname]] of the target<nowiki>></nowiki> (leave blank, or just exclude it, to use the player); | ||
*# < | *# <b>StartCatchThrowBehavior</b> <nowiki><name of the prop></nowiki> to switch to his play AI (leave blank to search for an object dynamically); | ||
That should be enough for the basic routine. | That should be enough for the basic routine. | ||
Other inputs can modify or stop it: | Other inputs can modify or stop it: | ||
* < | * <b>SetPickupTarget</b> <nowiki><name of the prop></nowiki> overrides his preferred prop; makes him stop waiting to catch - can be used to make him throw props in rapid succession; | ||
* < | * <b>SetThrowArcModifier</b> <nowiki><</nowiki>[[float]]<nowiki>></nowiki> alters the throw trajectory (values ''close'' to 0 make for a flat trajectory; >1 for tall parabolic trajectories; <=0 also make for very tall, potentially uncapped trajectories); | ||
* < | |||
* <b>StartWaitAndCatch</b> coupled with <b>PlayerPickupObject</b>; the former allows Dog to wait for a specific prop indefinitely, not giving up and finding another. The latter is meant to be fired from that specific prop, so that Dog knows the player has it. Use it before <b>StartCatchThrowBehavior</b>, or re-fire that one afterward (with the name of the prop as the input parameter); | |||
* <b>StopWaitAndCatch</b> disables indefinite wait for a specific prop; | |||
* <b>StopCatchThrowBehavior</b> makes stop altogether. | |||
==Known issues== | ==Known issues== | ||
{{ | {{warning|If '''Dog''' has an active [[ai goal follow|follow behavior]] (the only extra behavior he's capable of), he will prioritize it, and will not be able to use his fetching behavior. Turning it off (with <code>deactivate</code> input) allows him to play fetch.}} | ||
{{bug|hidetested=1|Sometimes, D0G might not start playing catch-and-throw even when everything is in place (all the inputs have been fired, there's valid [[nodegraph]], etc.), until his AI updates.}} | |||
{{fix|To ensure it, you can make him move by using an [[aiscripted_schedule]], [[scripted_sequence]] or a [[logic_choreographed_scene|choreo scene]]; just a short distance should be sufficient.}} | |||
If D0G waits too long, he'll give up and search for another prop. His heuristics isn't perfect, and it may lead to unindended consequences and even get him stuck, if he tries to grab a prop that's lodged in scenery, tied to [[phys_constraint|constraints]] and otherwise not meant for him. There doesn't seem to be a way to filter out what prop he can grab without additional programming, so you'd have to plan for it by not having any unintended physics lying around, or disabling their motion. | If D0G waits too long, he'll give up and search for another prop. His heuristics isn't perfect, and it may lead to unindended consequences and even get him stuck, if he tries to grab a prop that's lodged in scenery, tied to [[phys_constraint|constraints]] and otherwise not meant for him. There doesn't seem to be a way to filter out what prop he can grab without additional programming, so you'd have to plan for it by not having any unintended physics lying around, or disabling their motion. | ||
Line 38: | Line 44: | ||
* Are heavier than 250kg (this figure is hardcoded); | * Are heavier than 250kg (this figure is hardcoded); | ||
* Aren't [[visibility|visible]] to him; | * Aren't [[visibility|visible]] to him; | ||
* Are placed above his eye position. | * Are placed above his [[$eyeposition|eye position]]. | ||
{{bug|While D0G is capable of playing | {{bug|hidetested=1|While D0G is capable of playing catch-and-throw with a target other than the player (even another D0G),{{ref|1}} he'll always turn to face the player before throwing.}} | ||
==References== | ==References== | ||
# {{youtube|pyvAJlF8Jfg|page=watch| Two npc_dogs playing fetch with each other}} on '''YouTube''' | # {{youtube|pyvAJlF8Jfg|page=watch| Two npc_dogs playing fetch with each other}} on '''YouTube''' |
Latest revision as of 07:22, 20 May 2025
Overview
D0G's AI is largely dedicated to picking up physics objects and playing fetch with a target (usually, the player).
As shown in Half-Life 2, D0G can grab objects with his built-in Gravity Gun, toss them over an arcing trajectory, wait for it to be thrown back at him, and either repeat that cycle, or search for a new object dynamically.
While the logics setup used in Eli's junkyard (d1_eli_02) might seem frighteningly complex, a large portion of it has to do with spawning new crates dynamically, and tracking their fate (enabling D0G to act disappointed or excited), and then switching to play with his deactivated Rollermine. As well as a handful of scripts related to Alyx.
Scripting
The actual setup to play fetch with D0G is not that complicated:
- Use npc_dog in his most basic 'configuration', that is - not distracted by combat, scripted sequences, or follow behavior; all of them usually make his AI switch away from the catch-and-throw game.
- Have prop physics available to him.
- Now use the following Inputs to make him play fetch:
- SetThrowTarget <targetname of the target> (leave blank, or just exclude it, to use the player);
- StartCatchThrowBehavior <name of the prop> to switch to his play AI (leave blank to search for an object dynamically);
That should be enough for the basic routine.
Other inputs can modify or stop it:
- SetPickupTarget <name of the prop> overrides his preferred prop; makes him stop waiting to catch - can be used to make him throw props in rapid succession;
- SetThrowArcModifier <float> alters the throw trajectory (values close to 0 make for a flat trajectory; >1 for tall parabolic trajectories; <=0 also make for very tall, potentially uncapped trajectories);
- StartWaitAndCatch coupled with PlayerPickupObject; the former allows Dog to wait for a specific prop indefinitely, not giving up and finding another. The latter is meant to be fired from that specific prop, so that Dog knows the player has it. Use it before StartCatchThrowBehavior, or re-fire that one afterward (with the name of the prop as the input parameter);
- StopWaitAndCatch disables indefinite wait for a specific prop;
- StopCatchThrowBehavior makes stop altogether.
Known issues

deactivate
input) allows him to play fetch.

If D0G waits too long, he'll give up and search for another prop. His heuristics isn't perfect, and it may lead to unindended consequences and even get him stuck, if he tries to grab a prop that's lodged in scenery, tied to constraints and otherwise not meant for him. There doesn't seem to be a way to filter out what prop he can grab without additional programming, so you'd have to plan for it by not having any unintended physics lying around, or disabling their motion.
D0G won't attempt to grab objects that are:
- Flagged as debris or interactive debris;
- Held by the player;
- Have their motion disabled;
- Are heavier than 250kg (this figure is hardcoded);
- Aren't visible to him;
- Are placed above his eye position.

References
Two npc_dogs playing fetch with each other on YouTube