Sleeping AI

From The DarkMod Wiki
Jump to: navigation, search

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

This is done by targeting a path_sleep entity which then targets a path_wait to define how long they will sleep before getting up again.

Sleep Location

sleep_location 0 - sleep on the floor

sleep_location 1 - sleep on a bed

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:

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 immedaitely 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 (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 (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)

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'

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.

Known bugs

AI have their eyes closed now while sleeping. This is using the pain anim as a place holder at the moment, since we don't have a suitable anim yet (sleeping looks like a quite painful experience now...)

Another problem is that the bounding box stays behind and is solid when the AI goes to bed.

When you KO a sleeping AI, they may drop down through the bed, pop back to standing, like they did in Thief,

Also this is probably unrelated but might be contributing to this problem: I'm noticing that KO'd AI are sometimes(?) flashing into the AF pose for just a frame, then back to the pose they were in before KO'ing. You can see it if you watch really closely.

There is also a problem when they see the player while laying down - they jump up for a moment, then finsih putting themselves to bed and then finally get up to chase the player.