In my game I have customers who can lie on beds / sofas in their rented apartment.
In order to create the effect of a player sleeping / sitting down, I weld them to an invisible part and then play an animation. In this case, the invisible part is just above the bed so that they are animated to look to be lying / sitting on the bed
This solution is great, however, there is a problem when I delete the weld and stop the animation. My script then tries to move the NPC using pathfinding, however, just after the weld is deleted / animation stopped, the player gets stunned and won’t be able to move. Sometimes the NPC will just fall flat on its face, and take a few seconds to get back up again. By which time the pathfinding script’s ‘path block detector’ figures that it can’t move the NPC, so it destroys itself.
GIF example of it NOT working:
What it SHOULD be doing (and sometimes does):
You can see in the top GIF that the player gets stunned, no movement animations play, and almost falls over. But in the bottom GIF, it works perfectly and the player just walks away from the bed. That is the intended behaviour. Sometimes it will work, sometimes not. Could be due to player sizing etc, but still, not a true solution really.
I think that it is because due to the bed being anchored, as when the weld gets deleted and the animation stopped the player’s body might collide with the bed. Obviously I don’t really want to unanchor the beds, which is why I’ve come here to see if there are any other solutions.
Am I doing this wrong from the start by welding the player to a part? Is there a way to stop the player from being stunned once the weld is destroyed and animation stopped?
So what you can try to do is moving the npc a bit up after you unweld it. Setting his root position a bit up should cancel that effect. Or anchor the root for like 0.1/0.5 seconds.
Move the NPC to the side of the bed when you unweld them. I assume pathfinding can’t find a path sometimes due to the bed which is why it’s inconsistent.
You can also try making the NPC walk to the exit directly using Humanoid:MoveTo() without using pathfinding to pinpoint if it’s a problem with humanoids/the welds or your pathfinding script.
Would it not make more sense to anchor the HumanoidRootPart and then CFrame it? I feel like welds are unnecessarily here and are probably causing your problem.
That is also something I have tried but the NPC will still fall over afterwards, even when you teleport the player to a location above the bed as @jcnruad900 said so they do not collide with it.
Can u try set the root part to a color and do a video to it while it wakes up from the bed? Also how many times it wakes up in the right way and how many times it doesn’t wake up in the right way.
Oh, I think it gets stunned due to the inclined root, a time I messed up with my character root, inclining it or it got stunned or it stood up istantly. Infact in the video the root is inclined.
This looks a lot like platform standing to me. Platform standing disables humanoid physics, which looks like what’s happening where. Are you 100% it never changes?
You may try set the vertical orientation(using cframe) to 0, it should prevent the humanoid from getting stunned. Also it’s not platform standing because in platform standing legs would collide with the bed.
Instead of using an invisible part and welding it , you could use seats to make it non-buggy and much more simple , you can force a certain animation on the NPC while it is seated , and when it’s done playing just do
workspace.NPC.Humanoid.Jump = true
Which will cause the weld to automatically break without causing any problems to the NPC , while also providing a smooth animation between sitting and getting up