Sleeping AI: Difference between revisions
m →Known bug: Add xref to Sitting Behavior for AI#Problematic Behaviors |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 14: | Line 14: | ||
==Patrol Sleepers== | ==Patrol Sleepers== | ||
First, carefully position a path_corner relative to where the AI will sleep. Have this target a path_sleep entity. This in turn targets a path_wait that defines how long the AI will sleep before getting up again. | |||
==Sleep Location== | ==Sleep Location== | ||
Line 55: | Line 55: | ||
==Problems, Troubleshooting== | ==Problems, Troubleshooting== | ||
There are a few known problems: | There are a few known problems (and see also "Known Bugs" at page end): | ||
===AI is sinking into the bed or floating high=== | ===AI is sinking into the bed or floating high=== | ||
Line 110: | Line 110: | ||
This method replaces the "sleeping on a bed" behaviour. This means that the spawnarg "sleep_location" has to be set to "1". Setting it to 0 will still lead to the AI sleeping on the ground. The AI will only be able to sleep in a sitting position as long as the entity "atdm:animation_sleep_sit" is attached to it. Removing the entity will revert the sleeping behaviour, so the AI will sleep on a bed again. | This method replaces the "sleeping on a bed" behaviour. This means that the spawnarg "sleep_location" has to be set to "1". Setting it to 0 will still lead to the AI sleeping on the ground. The AI will only be able to sleep in a sitting position as long as the entity "atdm:animation_sleep_sit" is attached to it. Removing the entity will revert the sleeping behaviour, so the AI will sleep on a bed again. | ||
The AI sitting down is part of the sleeping behaviour, much like it is part of "sleeping on the bed". This means, with this method the AI will sit down and | The AI sitting down is part of the sleeping behaviour, much like it is part of "sleeping on the bed". This means, with this method the AI will sit down and immediately go to sleep. It is ''NOT'' possible to play other sitting animations in between. | ||
<span style="color: red">The following pertains to TDM versions 2.06 or later</span> | <span style="color: red">The following pertains to TDM versions 2.06 or later</span> | ||
Line 116: | Line 116: | ||
Use this sequence of path nodes if you want a patrolling AI to sit and take a nap for a while, then resume his patrol: | Use this sequence of path nodes if you want a patrolling AI to sit and take a nap for a while, then resume his patrol: | ||
* path_corner (AI walks to this) | * path_corner in front of the chair (AI walks to this) | ||
* path_sit ('angle' provides the sitting angle) | * path_sit ('angle' provides the sitting angle) | ||
* path_sleep ('sleep_location' '2' tells the AI to fall asleep after sitting) | * path_sleep ('sleep_location' '2' tells the AI to fall asleep after sitting) | ||
Line 124: | Line 124: | ||
Use this sequence of path nodes if you want the AI to stay seated after he wakes up: | Use this sequence of path nodes if you want the AI to stay seated after he wakes up: | ||
* path_corner (AI walks to this) | * path_corner in front of the chair (AI walks to this) | ||
* path_sit ('angle' provides the sitting angle) | * path_sit ('angle' provides the sitting angle) | ||
* path_sleep ('sleep_location' '2' tells the AI to fall asleep after sitting) | * path_sleep ('sleep_location' '2' tells the AI to fall asleep after sitting) | ||
* path_wait ('wait' and 'wait_max' determine how long the AI sleeps) | * path_wait ('wait' and 'wait_max' determine how long the AI sleeps) | ||
* path_wakeup (he will wake up and not stand up) | * path_wakeup (he will wake up and not stand up) | ||
For an AI spawned near the chair, still provide the path_corner and direct the AI to it. | |||
The 'angle' on the path_sit influences not just the sitting down, but the later standing up. | |||
Use these spawnargs on an AI who will start a mission sitting and sleeping, and will stay that way until roused: | Use these spawnargs on an AI who will start a mission sitting and sleeping, and will stay that way until roused: | ||
Line 134: | Line 138: | ||
* 'sleep_location' '2' | * 'sleep_location' '2' | ||
* 'sleeping' '1' | * 'sleeping' '1' | ||
'''NOTE''': If you use this method instead of the path nodes, when the AI wakes up it will pivot as if getting off of a bed. To avoid this, use the path nodes method instead. | |||
In contrast to the system used in version 2.05 and earlier, it is possible to interrupt other sitting behaviour like reading or writing with the sleeping behaviour. The earlier versions only allowed for an AI to directly sit down and sleep, then wake up and stand up again. | In contrast to the system used in version 2.05 and earlier, it is possible to interrupt other sitting behaviour like reading or writing with the sleeping behaviour. The earlier versions only allowed for an AI to directly sit down and sleep, then wake up and stand up again. | ||
Line 148: | Line 154: | ||
==Known bugs== | ==Known bugs== | ||
''As of 2022 and TDM 2.10'' | |||
* Bug 5268: An AI sits down in a chair. When he goes to leave, he gets stuck on chair, treadmilling. (This is not sleeping-specific. Seen in 2.07, "resolved" in name only. No viable code solution found, only map-tweaking workaround.) | |||
* [https://forums.thedarkmod.com/index.php?/topic/9082-newbie-darkradiant-questions/&do=findComment&comment=477150 Frost Salamander reported] that sleeping AI (in chair or bed, with usual path nodes) sometimes die if KO'd. They seem to taking damage which varies dramatically, possibly from KO-caused interaction with nearby geometry. (That interaction could be a simple bounce; in the past, KOs of sleepers caused other oddities: clipping through bed; a 1-frame reversions to an AF pose). Suggested workarounds: | |||
** move the chair or bench further away from other geometry such as walls. | |||
** don't let the AI touch the bed or chair (causing an undesirable air gap). | |||
** use a moveable chair - though if the player moves the chair, the AI can end up sitting on air. | |||
For another take about these behaviors and solutions, see [[Sitting Behaviour for AI#Problematic Behaviours]]. | |||
{{tutorial-ai}} | {{tutorial-ai}} |
Latest revision as of 17:50, 15 January 2023
Introduction
Sleeping AI are (mostly) working now. They can either put themselves to bed at map start and remain there (unless alerted) or else patrol, sleep for a while, then patrol again.
Non-patrolling sleepers
These are defined as sleepers at the start and immediately lay down. They only will get up if alerted.
Set on the AI the spawn arg:
sleeping 1
Patrol Sleepers
First, carefully position a path_corner relative to where the AI will sleep. Have this target a path_sleep entity. This in turn targets a path_wait that defines how long the AI will sleep before getting up again.
Sleep Location
sleep_location 0 - sleep on the floor
sleep_location 1 - sleep on a bed
sleep_location 2 - sleep on a chair (further details below)
Setting up
By default, place the AI on the right side of the bed (as you look towards the head of the bed) and facing away from the bed.
Direction
If you want the AI to start from the left side of the bed (as you look towards the head of the bed) then add:
lay_down_left 0 (note this goes on the AI if the AI is using sleeping 1 BUT on the path_sleep if you are using a path_sleep)
Sleeping position in the bed
Head to Toe
Stand the AI close to the bed facing away from it and about half way between the head and the foot; adjust as needed towards the head or foot direction of the bed.
Sideways
The distance the AI slides across onto the bed can be controlled by
lay_down_slide_dist 16 (default)
(note this goes on the AI if the AI is using sleeping 1 BUT on the path_sleep if you are using a path_sleep)
Monster clip the bed or not?
Yes, monster clip should not directly affect the sleep animation and the bed should normally be monsterclipped anyway. The only way it might affect it is if the clip sticks out too far and stops the AI getting near enough. In that case reduce the clip close to the bed edge and/or adjust the slide value (see #Sleeping position in the bed)
Problems, Troubleshooting
There are a few known problems (and see also "Known Bugs" at page end):
AI is sinking into the bed or floating high
AI animate to the same height so if they are slightly high the first thing to check is the bed surface height. Most Dark Mod beds are a standard height which is correct for sleepers. One known bed (at time of writing) is a little high so AI will animate into it so be sunk a little low. This bed can be sunk a little into the floor to compensate. If they are floating slightly high then the bed can be lifted a little and perhaps some wood brushes under the legs make it right.
If the AI are floating very high then this is most likely caused by the AI clipping into the bed at the start so they are lifted up to stand on its edge before they animate. They then animate up even higher. Solution: move them further out at the start. Note: this problem probably only affects AI that start off sleeping rather than patrol to a bed.
AI lays down too far to one side of the bed
To move an AI across the bed see #Sleeping position in the bed
AI lays wrong way head to foot
If the AI is laying the wrong way with his head at the foot of the bed and his feet at the head then see #Direction
Sleeping While Sitting
The following pertains to TDM versions 2.05 or earlier. See below for 2.06 and later behavior.
It is also possible to put an AI to sleep on a chair. This requires a more elaborate setup than the regular sleeping while lying down, as the animations of the sleeping behaviour have to be exchanged. In order to achieve this, a dummy entity is required. Up to now, this entity is not part of the core mod, so the following has to be copy/pasted into a def file, that then has to be put into the folder "def" of the mod or the FM that uses it:
entityDef atdm:animation_sleep_sit { "inherit" "atdm:prop_base" "editor_usage" "Used to make AI sleep in a sitting position instead of laying down" "model" "models/darkmod/misc/system/empty.lwo" "joint" "RightHand" "replace_anim_sit_2_sleep_lft" "sit_2_sleep_on_chair" "replace_anim_sit_2_sleep_rgt" "sit_2_sleep_on_chair" "replace_anim_sleep_idle_lft" "sit_sleep_idle" "replace_anim_sleep_idle_rgt" "sit_sleep_idle" "replace_anim_sleep_2_sit_lft" "sleep_2_sit_on_chair" "replace_anim_sleep_2_sit_rgt" "sleep_2_sit_on_chair" "origin" "0 0 0" "angles" "0 0 0" "remove" "0" }
The AI has to get the following spawnargs:
"def_attach5" "atdm:animation_sleep_sit" "pos_attach5" "hand_r" "lay_down_slide_dist" "0"
The first two spawnargs attach the dummy entity to the AI, while the third spawnarg prevents the AI from sliding into the chair. This method works with both patrol sleepers as well as non-patroling AI.
PLEASE NOTE:
This method replaces the "sleeping on a bed" behaviour. This means that the spawnarg "sleep_location" has to be set to "1". Setting it to 0 will still lead to the AI sleeping on the ground. The AI will only be able to sleep in a sitting position as long as the entity "atdm:animation_sleep_sit" is attached to it. Removing the entity will revert the sleeping behaviour, so the AI will sleep on a bed again.
The AI sitting down is part of the sleeping behaviour, much like it is part of "sleeping on the bed". This means, with this method the AI will sit down and immediately go to sleep. It is NOT possible to play other sitting animations in between.
The following pertains to TDM versions 2.06 or later
Use this sequence of path nodes if you want a patrolling AI to sit and take a nap for a while, then resume his patrol:
- path_corner in front of the chair (AI walks to this)
- path_sit ('angle' provides the sitting angle)
- path_sleep ('sleep_location' '2' tells the AI to fall asleep after sitting)
- path_wait ('wait' and 'wait_max' determine how long the AI sleeps; he will wake up and stand up when finished)
- path_corner (AI walks to this)
Use this sequence of path nodes if you want the AI to stay seated after he wakes up:
- path_corner in front of the chair (AI walks to this)
- path_sit ('angle' provides the sitting angle)
- path_sleep ('sleep_location' '2' tells the AI to fall asleep after sitting)
- path_wait ('wait' and 'wait_max' determine how long the AI sleeps)
- path_wakeup (he will wake up and not stand up)
For an AI spawned near the chair, still provide the path_corner and direct the AI to it.
The 'angle' on the path_sit influences not just the sitting down, but the later standing up.
Use these spawnargs on an AI who will start a mission sitting and sleeping, and will stay that way until roused:
- 'sleep_location' '2'
- 'sleeping' '1'
NOTE: If you use this method instead of the path nodes, when the AI wakes up it will pivot as if getting off of a bed. To avoid this, use the path nodes method instead.
In contrast to the system used in version 2.05 and earlier, it is possible to interrupt other sitting behaviour like reading or writing with the sleeping behaviour. The earlier versions only allowed for an AI to directly sit down and sleep, then wake up and stand up again.
Sleeping Warnings
In TDM 2.08, warnings have been added when an AI tries to play a sleeping animation in the wrong place. The warning looks like this:
"WARNING: <AI name> (x y z) can't sleep: too far from sleeping location <name of path_corner> (x y z)"
The first x/y/z vector is the AI's origin, and the second is the location of the path_corner where sleeping is supposed to take place. If the AI starts the mission sleeping (using the "sleeping" spawnarg), then no path_corner is involved, and no name will be given.
To correct this problem, examine the spot where the AI is supposed to sleep. Ill-used monster_clip is usually the problem.
Known bugs
As of 2022 and TDM 2.10
- Bug 5268: An AI sits down in a chair. When he goes to leave, he gets stuck on chair, treadmilling. (This is not sleeping-specific. Seen in 2.07, "resolved" in name only. No viable code solution found, only map-tweaking workaround.)
- Frost Salamander reported that sleeping AI (in chair or bed, with usual path nodes) sometimes die if KO'd. They seem to taking damage which varies dramatically, possibly from KO-caused interaction with nearby geometry. (That interaction could be a simple bounce; in the past, KOs of sleepers caused other oddities: clipping through bed; a 1-frame reversions to an AF pose). Suggested workarounds:
- move the chair or bench further away from other geometry such as walls.
- don't let the AI touch the bed or chair (causing an undesirable air gap).
- use a moveable chair - though if the player moves the chair, the AI can end up sitting on air.
For another take about these behaviors and solutions, see Sitting Behaviour for AI#Problematic Behaviours.