Sitting Behaviour for AI: Difference between revisions
Springheel (talk | contribs) |
m →Problematic Behaviours: UK spelling of behavior to be consistent |
||
(13 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
There are two different ways to get AI to sit in your map; pick the one that best suits your needs. | |||
==Sitting at Map Start== | ==Sitting at Map Start== | ||
Just set the spawnarg "sitting" "1" on the AI, and the AI will sit down immediately at map start. They will stay this way until alerted to the point of searching, at which point they will get up. After calming down, they will go back and sit again. | The easier of the two options. Just set the spawnarg "sitting" "1" on the AI, and the AI will sit down immediately at map start. They will stay this way until alerted to the point of searching, at which point they will get up. After calming down, they will go back and sit again. | ||
You must place the AI next to the chair, facing away from the direction you want him to sit (or use angles, see below). | |||
The code does not detect the surface the AI sits on, so he will sit on thin air if there is no stool or chair there. | |||
2.03 -- if you put "sitting" "1" on an AI and then target him at pathnodes that have an "alert_idle_only" "1" spawnarg on them, the AI will sit as long as he is not alert, but will start patrolling (and will no longer sit) once he is alerted. I'm not exactly sure why this works and the AI doesn't sit down at the new pathnodes he walks to, but this method seems to work well. | |||
==Sitting During Patrol== | ==Sitting During Patrol== | ||
It is now possible to have the AI sitting down and getting up during patrolling, using a '''path_sit''' entity. | It is now possible to have the AI sitting down and getting up during patrolling, using a '''path_sit''' entity paired with a '''path_corner'''. You can place the path_sit anywhere, angled away from the direction you want him to sit. The path_sit must be preceded by a path_corner, which is where you want him to stand when he begins the sitting animation. | ||
You can set "wait" and/or "wait_max" to let the AI wait and get up after that time. "Wait" is a minimum wait time, so if you set "wait" to 5 seconds and "wait_max" to 10 seconds, the AI will wait between 5 and 10 seconds every time. If you only set "wait", the AI will always wait exactly 5 seconds. If you only set "wait_max", the AI will wait between 0 and 10 seconds. | You can set "wait" and/or "wait_max" to let the AI wait and get up after that time. "Wait" is a minimum wait time, so if you set "wait" to 5 seconds and "wait_max" to 10 seconds, the AI will wait between 5 and 10 seconds every time. If you only set "wait", the AI will always wait exactly 5 seconds. If you only set "wait_max", the AI will wait between 0 and 10 seconds. | ||
Line 9: | Line 18: | ||
The AI will get up if alerted to searching state or if it has to move to another position. | The AI will get up if alerted to searching state or if it has to move to another position. | ||
Example: If you want an AI to sit, and then play a warm hands after 20 seconds, you would use a path_sit without a wait spawnarg (AI sits down, the path_sit task is terminated and the AI stays seated), then a path_wait for 20 seconds, then a path_anim, then another path_wait, and then a path_corner or something (AI gets up and walks to path_corner). | Example: If you want an AI to sit, and then play a warm hands after 20 seconds, you would use a path_sit without a wait spawnarg (AI sits down, the path_sit task is terminated and the AI stays seated), then a path_wait for 20 seconds, then a path_anim, then another path_wait, and then a path_corner or something (AI gets up and walks to path_corner). | ||
Line 19: | Line 25: | ||
== Sitting Angles == | == Sitting Angles == | ||
Mappers may want control over where AI face after sitting down. By default, AI stand directly in front of the | Mappers may want more control over where AI face after sitting down. By default, AI stand directly in front of the chair when sitting or standing. This doesn't work well if you want AI to sit close to a table, however. The solution is to use a "sit_down_angle" spawnarg on the AI (if AI has 'sitting' spawnarg but on the path_sit if that is used.) This will cause the AI to spin in the chair after sitting until they face the direction listed. They will turn back when it is time to stand up. | ||
Note that the angles are relative to the world, not the AI. | Note that the angles are relative to the world, not the AI. | ||
Line 26: | Line 32: | ||
"sit_down_slide_dist", which is currently 8; controls how far AI slide back onto the chair when sitting down. | "sit_down_slide_dist", which is currently 8; controls how far AI slide back onto the chair when sitting down. | ||
"sitting_turn_pivot" "The offset of the pivot for turning while seated." | |||
== Sitting Warnings == | |||
In TDM 2.08, warnings have been added when an AI tries to play a sitting animation in the wrong place. The warning looks like this: | |||
"WARNING: <AI name> (x y z) can't sit: too far from sitting 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 sitting is supposed to take place. If the AI starts the mission sitting (using the "sitting" 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 sit. Ill-used monster_clip is usually the problem. | |||
== Problematic Behaviours == | |||
If the body of a sitting or sleeping AI overlaps with the chair/bed or other furniture (e.g., table), this can cause problems. The only solution is to iteratively adjust the position of the AI and/or furniture, until the problem "goes away". Specific examples: | |||
* ''Treadmilling Upon Arising.'' Here, an AI first sits down on a chair, then, when going to leave, gets stuck on the chair and treadmills. | |||
* ''Dying After Knock Out.'' If you knock out a sitting (or sleeping) AI, it may jump up and instantly die. Likely the AI is a bit into the furniture. Presumably this makes the KO'd AI flail about and physics take over; the rapid movement damages and quickly kills the AI. | |||
* For another take on these behaviours and their solution, see [[Sleeping AI#Known bugs]]. | |||
{{tutorial-ai}} | {{tutorial-ai}} |
Latest revision as of 17:50, 15 January 2023
There are two different ways to get AI to sit in your map; pick the one that best suits your needs.
Sitting at Map Start
The easier of the two options. Just set the spawnarg "sitting" "1" on the AI, and the AI will sit down immediately at map start. They will stay this way until alerted to the point of searching, at which point they will get up. After calming down, they will go back and sit again.
You must place the AI next to the chair, facing away from the direction you want him to sit (or use angles, see below).
The code does not detect the surface the AI sits on, so he will sit on thin air if there is no stool or chair there.
2.03 -- if you put "sitting" "1" on an AI and then target him at pathnodes that have an "alert_idle_only" "1" spawnarg on them, the AI will sit as long as he is not alert, but will start patrolling (and will no longer sit) once he is alerted. I'm not exactly sure why this works and the AI doesn't sit down at the new pathnodes he walks to, but this method seems to work well.
Sitting During Patrol
It is now possible to have the AI sitting down and getting up during patrolling, using a path_sit entity paired with a path_corner. You can place the path_sit anywhere, angled away from the direction you want him to sit. The path_sit must be preceded by a path_corner, which is where you want him to stand when he begins the sitting animation.
You can set "wait" and/or "wait_max" to let the AI wait and get up after that time. "Wait" is a minimum wait time, so if you set "wait" to 5 seconds and "wait_max" to 10 seconds, the AI will wait between 5 and 10 seconds every time. If you only set "wait", the AI will always wait exactly 5 seconds. If you only set "wait_max", the AI will wait between 0 and 10 seconds.
If you don't set either one, the AI will stay seated and you can also do path_anims and path_waits for example (they'll play that animation on the torso channel while sitting).
The AI will get up if alerted to searching state or if it has to move to another position.
Example: If you want an AI to sit, and then play a warm hands after 20 seconds, you would use a path_sit without a wait spawnarg (AI sits down, the path_sit task is terminated and the AI stays seated), then a path_wait for 20 seconds, then a path_anim, then another path_wait, and then a path_corner or something (AI gets up and walks to path_corner).
If you have any path problems, eg, with AI clipping into Monsterclip on chair, then make the chair a moveable and add frobable 0 and notPushable 1 and remove the monsterclip. It is effectively static but the AI will path it correctly without monsterclip.
Sitting Angles
Mappers may want more control over where AI face after sitting down. By default, AI stand directly in front of the chair when sitting or standing. This doesn't work well if you want AI to sit close to a table, however. The solution is to use a "sit_down_angle" spawnarg on the AI (if AI has 'sitting' spawnarg but on the path_sit if that is used.) This will cause the AI to spin in the chair after sitting until they face the direction listed. They will turn back when it is time to stand up.
Note that the angles are relative to the world, not the AI.
Other sitting spawnargs include:
"sit_down_slide_dist", which is currently 8; controls how far AI slide back onto the chair when sitting down.
"sitting_turn_pivot" "The offset of the pivot for turning while seated."
Sitting Warnings
In TDM 2.08, warnings have been added when an AI tries to play a sitting animation in the wrong place. The warning looks like this:
"WARNING: <AI name> (x y z) can't sit: too far from sitting 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 sitting is supposed to take place. If the AI starts the mission sitting (using the "sitting" 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 sit. Ill-used monster_clip is usually the problem.
Problematic Behaviours
If the body of a sitting or sleeping AI overlaps with the chair/bed or other furniture (e.g., table), this can cause problems. The only solution is to iteratively adjust the position of the AI and/or furniture, until the problem "goes away". Specific examples:
- Treadmilling Upon Arising. Here, an AI first sits down on a chair, then, when going to leave, gets stuck on the chair and treadmills.
- Dying After Knock Out. If you knock out a sitting (or sleeping) AI, it may jump up and instantly die. Likely the AI is a bit into the furniture. Presumably this makes the KO'd AI flail about and physics take over; the rapid movement damages and quickly kills the AI.
- For another take on these behaviours and their solution, see Sleeping AI#Known bugs.