Jump to content
The Dark Mod Forums

Sleeping Ai: get them to sleep on the ground


Bikerdude

Recommended Posts

Sorry to revive this thread, but I tried to get an AI to sleep while sitting. It does not appear to work by ticking "sitting" as well as "sleeping", so I set it up by using path nodes, because I want it to be part of a patrol later on. I used the path nodes "path_sit"->"path_wait" (just to male sure the AI finished sitting before going to sleep)->"path_anim (sit_2_sleep_on_chair)"->"path_cycleanim(sit_sleep_idle)" and it looks fine, but while the animation indicates that the AI is sleeping, it still appears to be able to see, which is of course not wanted. So, is there a way to set the AI "sleeping". Maybe a frame command that disables the FOV? I took a look at the other sleeping animations, but I only found the "sound" and "noclip" frame commands, which lets me believe that the "sleeping" is handled by the code? If it lies within my abilities I would be happy to set up the complete behaviour, but I have no idea where to start.

Link to comment
Share on other sites

Sleeping is handled by the code. It's possible to get them to sleep in a chair using an anim_replace spawnarg, but I'm sure there's an easier way that I just can't remember. If no one else chimes in, ask me about it.

 

I can't think of a map off the top of my head that uses a sitting sleeper, but if you know of one, you could open the map and look to see what spawnarg they put on him.

Link to comment
Share on other sites

Ok, so the anim_replace might be the only way to do this currently. I'm at work so I can't look up the specifics, but it would go something like this:

 

You make a dummy entity (I can provide an example when I get home) and def_attach it to the AI.

 

The dummy entity has the spawnarg "anim_replace_[regular sleep]" "[sitting sleep]" for each of the 3 relevant floor sleeping animations (stand to lie down, sleeping, lie down to stand up).

 

Then you put the spawnarg on the AI that tells him to sleep on the floor.

 

From the code perspective, the AI acts as if they are sleeping on the floor, but instead of playing those animations it will play the sit-sleeping animations instead. I can't vouch for sure that this works without any consequences. I don't know how the code establishes the character's origin while sleeping, for example. But that's how I'd attempt it.

 

If you are still interested, ping me in about 5 hours and I'll set up a prefab for you.

Link to comment
Share on other sites

From the code perspective, the AI acts as if they are sleeping on the floor, but instead of playing those animations it will play the sit-sleeping animations instead. I can't vouch for sure that this works without any consequences.

I would be interested to see how this works in-game, as I have wanted to do this in a few FM's before now.

Link to comment
Share on other sites

Ok, I have made the dummy entity (based on the "atdm:animation_replace_lean" definition) and put it in the tdm_prop_items.def:

 

 

entityDef atdm:animation_replace_sleep_sit {
"inherit" "atdm:prop_base"
"editor_usage" "Used to make AI lean back against a surface while idle. Put AI 25 units away from wall/surface. AI will stop leaning if alerted."
"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" "sit_sleep_idle"
"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"
// to ensure AI stops leaning if they are disturbed
"unbindOnalertIndex" "2"

}

 

 

I have used the sleeping animation of the bed, as this includes that the AI will sit down before sleeping (although I had to replace two animations that way). However, there are still two errors: For one, the AI slides and clips into the chair, when it falls asleep (although this may be corrected with a better positioning of the AI). The second problem is, that upon waking up, it still uses an animation, that starts in a laying position. Maybe only a typo, but still an error. Here is a small test map. For waking up the AI (with the same team as the player) I used a noise arrow:

 

test_sleep.map.txt

Link to comment
Share on other sites

Yeah, I wouldn't recommend using the regular sleep animations, because they include some hard-coded sliding to get the AI in the right position. Try the floor sleeping ones.

Link to comment
Share on other sites

Before, I forgot to reply to previous posts, so here goes:

There's no code or script support for sleeping while sitting. This issue is almost 3yo, and never rose to the top of my todo list.

 

I don't know if I'll get to it in 2.06, because I'm focused elsewhere.

 

Someday.

No problem. It is definitely not the most pressing matter and I know that the number of coders is dwindling, unfortunately.

 

Ok, so the anim_replace might be the only way to do this currently. I'm at work so I can't look up the specifics, but it would go something like this:

 

You make a dummy entity (I can provide an example when I get home) and def_attach it to the AI.

 

The dummy entity has the spawnarg "anim_replace_[regular sleep]" "[sitting sleep]" for each of the 3 relevant floor sleeping animations (stand to lie down, sleeping, lie down to stand up).

 

Then you put the spawnarg on the AI that tells him to sleep on the floor.

 

From the code perspective, the AI acts as if they are sleeping on the floor, but instead of playing those animations it will play the sit-sleeping animations instead. I can't vouch for sure that this works without any consequences. I don't know how the code establishes the character's origin while sleeping, for example. But that's how I'd attempt it.

 

If you are still interested, ping me in about 5 hours and I'll set up a prefab for you.

Thanks for your offer, I still don't really understand, why I need the dummy entity, but it works (at least almost). I would be glad, if you could take a look at the files I posted before. Unfortunately, I am not sure, how much time I will have the rest of the day, but I will try to get the rest working tomorrow ot the latest the day after that.

 

I would be interested to see how this works in-game, as I have wanted to do this in a few FM's before now.

With the def-attach approach, it should not be too big a problem. If you need other sleeping animations beside it (which I don't), it should be possible to detach the dummy prop and reattach it, when needed. This will need further testing, of course...

Link to comment
Share on other sites

Thanks for your offer, I still don't really understand, why I need the dummy entity

 

 

You're right, it might work just putting those spawnargs on the AI itself. I'm used to doing it that way so you can cancel the behaviour by removing the attached entity, but with sleeping that's probably not necessary.

Link to comment
Share on other sites

That depends, if the patrol should include other sleeping positions or not. Also this way may be easier for other mappers to implement it, so it is fine.

 

Yeah, I wouldn't recommend using the regular sleep animations, because they include some hard-coded sliding to get the AI in the right position. Try the floor sleeping ones.

This would explain the sliding into the chair. How can I add the "sit_down" animation between standing in front of the chair and falling asleep? Or should I try it via path nodes and first let him sit down and then sleep?

Link to comment
Share on other sites

Tell me exactly what you want the AI to do. Does he stay in the chair the whole time unless alerted?

Link to comment
Share on other sites

Ideally, I would like the AI to patrol, at some point sit down, fall asleep and after some time get up and continue patroling. So, it is replacing the AI sleeping behaviour from sleeping in a bed or on the floor inwith sleeping in a chair. However, I think that, if I replace the stand_2_sleep animation with sit_2_sleep_on_chair, the AI would not sit down before playing the animation and thus will snap into the sitting position. This is why I thought it would be preferable to use the sit_2_sleep_lft/rgt animations and "sleep_location" "1" as this includes sitting down before sleeping (which is missing for "sleep_location" "0"). I did not know about the hard-coded sliding, though.

Link to comment
Share on other sites

I'm not sure you can do what you want very easily with the existing setup. When the AI starts to engage floor sleeping behaviour, they play 2 animations:

 

(names aren't precise)

 

1. stand to lie down

2. immediately play lie down sleeping and enter sleep mode

3. If alerted, play lie down to stand up.

 

You can replace the animations with:

 

1. Stand to sit

2. immediately play sitting sleep and enter sleep mode

3. if alerted, play sit to stand

 

However, the problem might be the word "immediately" in #2. There is no way that I know of to add a delay, and it won't look very believable if he walks over, sits and is asleep 1 second later.

 

You can have an AI that starts asleep already with this method, but I'm not sure it suits patrolling.

Link to comment
Share on other sites

As far as I understand it, the animations are for sleeping on the floor are: stand_2_sleep->sleep_idle->sleep_2_stand. When I replace them accordingly I get sit_2_sleep->sit_sleep_idle->sleep_2_sit. When this is part of a patrol, the AI sits very abruptly, immediately falls asleep and when the patrol continues wakes up and stands very abruptly. It does not look very good. When I replace sit_2_sleep_lft/rgt->sleep_idle_llft/rgt->sleep_2_sit_lft/rgt with the setup above, it looks much better, because the AI plays the sit down and stand up animation. The problem here is the hard-coded slide, that lets it clip into the chair. The final problem is: As soon as the AI is alarmed instead of simply continuing on its path, the sleep_2_stand animation is played (even though it should have been replaced).

 

So as far as I can tell, replacing the sleeping behaviour is not possible. Another idea I have would be: use the regular "sitting" behaviour of the AI and play the animations via "path_anim". The only thing I need to accomplish the illusion of sleep is: disable the AI's sight and manually set the AI's eyes as closed for the time the "sleep_idle" animation plays. Do you have any idea if this is possible with script commands? Disabling sight should be (this should be used in flash bombs, for example), but the eyes may be a problem.

Link to comment
Share on other sites

I can't help with the scripting questions, other to point out that closing the eyes requires an animation on the head channel.

 

However, if you have things working the way you want other than the sliding...there is a spawnarg that controls how much sliding the AI does while sleeping. Maybe you can find a value that looks good? That's my last idea.

Link to comment
Share on other sites

The lay_down_slide_dist did the trick. Strangely, this should have gone onto the path_sleep node (according to the Wiki), but it only worked on the AI. Anyway, it works :). Well, at least as long as the AI does not get alarmed. In this case, the AI jumps to another animation, that I could not determine so far. Currently it looks as if the AI falls through the chair onto the floor and tehn gets up. But this has already helped a lot. Thank you very much!

  • Like 1
Link to comment
Share on other sites

I finally found out what caused the error of jumping to the laying down animation: The definition I copied had the "drop_when_alerted" spawnarg. As a consequence, when the AI got alerted, the entity immediately got detached, so the "stand up" animation (that played after being alerted) used the replaced animation. After removing this spawnarg, the system appears to work without problems now :)

So, if anyone wants to use a sitting AI, you can use this dummy entity, by copy/pasting it into a def-file:

 

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" "sit_sleep_idle"
"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"
}

 

Then you have to def_attach the entity to the AI you want to sleep in a sitting position by giving the AI the spawnargs "def_attach5" "atdm:animation_sleep_sit" and "pos_attach" "hand_r". Furthermore the AI will need the spawnarg "lay_down_slide_dist" "0" (contrary to what the wiki states, this spawnarg has to go on the AI, regardless of using a path_sleep or the sleeping spawnarg) or it will slide into the chair it is sitting on. To send the AI to sleep both the spawnarg "sleeping" "1", as well as a path_sleep methods are possible. EDIT: I forgot: I have replaced all laying sleeping animations, so it does not matter, which "sleep_location" is used.

 

The only downside I see for this method right now is that the AI sits down and directly goes to sleep. As this setup uses sleeping behaviour, it is not possible for the AI to directly go to sleep from the sitting position without coding support (as far as I can tell). This means it is not possible that the AI sits down in order to write (or play any other sitting animation) and then at some point just fall asleep. It will have to stand up first, then sit down and fall asleep. Still, it can be used for example for guards, who fell asleep on duty and start patroling after that or something similar. With the dummy entity it should also be possible to have both sitting and laying behavior by dropping and reattaching the dummy entity. However, I have not yet tested this. Now that I think about it, this might even be a way to circumvent the going directly to sleep behaviour: The AI starts sleeping on a chair, gets alerted and then decides, as it fell asleep before, to go to bed rather than sitting down again (an alert_idle path node should do the trick here).

EDIT2: I could also make two entities, so only one of the laying sleeping behaviours is changed. That way the AI may sleep on a bed / on the floor and in a chair without dropping the dummy entity and the behaviour can be changed by changing the sleeping_location.

 

Another question: Should I add this to the "Sleeping AI" Wiki page for future reference?

Edited by Destined
  • Like 1
Link to comment
Share on other sites

Another question: Should I add this to the "Sleeping AI" Wiki page for future reference?

 

 

 

That would be great. It will quickly get lost here.

Link to comment
Share on other sites

I have another question regarding the dummy entity: How can I remove a def_attached entity? I wanted to try to revert the sleeping behaviour and have given the AI a response(trigger) with remove: atdm:animation_sleep_sit. Then I have created a path_corner which triggers the AI. However, this did not revert the sleeping behaviour and the most likely error is, that I made a mistake with the setup, as I am not sure how to target an entity that was not put into the map with DR.

Link to comment
Share on other sites

I have changed the setup, so I don't have to target a def_attached entity by creating the atdm:animation_sleep_sit in DR and binding it to the AI. However, I have noticed that the "trigger" spawnarg on the path_corner appears to not be recognised as a trigger stim. After some more trying around, I finally got it all to work, but found one big flaw in the plan: the AI has to be have the lay_down_slide_dist to "0" to not clip into the chair, but it needs this spawnarg to correctly lie on a bed, so I have given up on this underatking for now...

Edited by Destined
Link to comment
Share on other sites

I'm impressed you got as far as you did, knowing all the intricacies in the code and scripts for dealing with lie-down sleeping.

 

I'll get a working version into 2.06 that won't require def-attachments or doubling up the meaning of spawnargs.

 

We have no release date for 2.06, though.

  • Like 2
Link to comment
Share on other sites

Thanks! However, it was mainly trial and error and I would not have been able to do it without the input I got here.

It would be great, if it were possible to activate the sleeping behaviour directly from the sitting behaviour. In that case, it would be possible for the AI to appear to work on a table and (due to the late hour), fall asleep at some point. Later on, it can wake up and continue, what it was doing. I do not know the intricacies of the code adn thus I have no idea how viable this is, so please see it as a suggestion in case it is not too difficult to implement, as I am sure there are still more pressing matters for you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recent Status Updates

    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 1 reply
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 3 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
×
×
  • Create New...