Jump to content


Photo

Sleeping Ai: get them to sleep on the ground


73 replies to this topic

#51 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 03:24 AM

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.



#52 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 07:36 AM

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.



#53 grayman

grayman

    Master Builder, Coder

  • Active Developer
  • PipPipPipPipPip
  • 11789 posts

Posted 17 May 2017 - 09:39 AM

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.



#54 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 09:52 AM

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.



#55 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18546 posts

Posted 17 May 2017 - 10:03 AM

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.



#56 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 11:09 AM

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

Spoiler

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:

 

Attached Files



#57 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 11:12 AM

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.



#58 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 11:13 AM

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...



#59 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 11:16 AM

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.



#60 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 11:24 AM

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?



#61 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 11:28 AM

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



#62 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 11:54 AM

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.



#63 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 12:03 PM

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.



#64 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 12:35 PM

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.



#65 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 17 May 2017 - 01:00 PM

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.



#66 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 17 May 2017 - 01:22 PM

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!


  • Springheel likes this

#67 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 19 May 2017 - 02:42 AM

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:

Spoiler

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, 19 May 2017 - 02:49 AM.

  • Anderson likes this

#68 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36377 posts

Posted 19 May 2017 - 07:07 AM

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.



#69 grayman

grayman

    Master Builder, Coder

  • Active Developer
  • PipPipPipPipPip
  • 11789 posts

Posted 19 May 2017 - 08:05 AM

Please make sure the cons are documented, since I'll need to address them when I eventually get around to implementing the code/script solution.



#70 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 19 May 2017 - 10:25 AM

I have added a "Sleeping While Sitting" section on the Sleeping AI Wiki page. Please proof read it, if I have made any mistakes or forgotten anything. I am acutally not sure what the "remove" "0" spawnarg does, but it was on the dummy entity I used, so I kept it.


Edited by Destined, 19 May 2017 - 10:27 AM.

  • Anderson likes this

#71 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 20 May 2017 - 05:06 AM

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.



#72 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 20 May 2017 - 10:58 AM

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, 20 May 2017 - 10:59 AM.


#73 grayman

grayman

    Master Builder, Coder

  • Active Developer
  • PipPipPipPipPip
  • 11789 posts

Posted 21 May 2017 - 09:26 AM

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.


  • Anderson and Destined like this

#74 Destined

Destined

    Advanced Member

  • Member
  • PipPipPip
  • 1234 posts

Posted 21 May 2017 - 09:58 AM

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.





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users