Stand Back Up! How to Reverse Ragdoll Physics (Unity Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ต.ค. 2024
  • In this Unity tutorial we're going to to look at how we can reverse ragdoll physics, and have the character stand back up again.
    The project files are available to our patrons here:
    ► / 71972693
    Want to follow along? This project is a good starting point
    ► / project-files-68074022
    The final script can be found here
    ► dotnetfiddle.n...
    Help support our work:
    ► Patreon: / ketragames
    ► Ko-fi: ko-fi.com/ketr...
    Follow us:
    ► Ketra Games: www.ketra-games...
    ► Patreon: / ketragames
    ► Twitter: / ketragames
    ► Facebook: / ketragames
    0:28 - Recap of ragdoll physics
    1:03 - First attempt at reversing the ragdoll
    2:57 - Understanding why it didn't work
    3:38 - Realigning the zombie position
    6:00 - Adding a stand up animation
    11:05 - Transitioning to the stand up animation
    20:30 - Improving the bone transitions
    23:58 - Finishing touches
    24:52 - Summary
    #KetraGames #LearnUnity #UnityTutorials #UnityTips

ความคิดเห็น • 117

  • @zaba_dev
    @zaba_dev ปีที่แล้ว +4

    If its still sliding and you've copy pasted the code from the link in the description, check your transform scales. Make everything 1,1,1. My armature object was scaled up. Lost a solid day of my life trying to figure that out. But got it now!

  • @kdawg717
    @kdawg717 9 หลายเดือนก่อน +1

    I watch a lot of tutorials. Most of them are very frustrating and lacking in one way or many. This tutorial is perfect.

    • @KetraGames
      @KetraGames  9 หลายเดือนก่อน

      Thanks so much for this comment, means a lot 😊

  • @mlgsquirrel
    @mlgsquirrel ปีที่แล้ว +4

    Underrated video, I haven't found any other video that explains the transitioning in detail, actually, I didn't find any video that transitions from ragdoll to animator. Thanks for making this.

  • @krawlak
    @krawlak 2 ปีที่แล้ว +11

    Cool video! Minor point: Random.Range(5, 10) uses the integer version of random, which returns one of 5, 6, 7, 8 or 9, excluding 10. If you want any float number up to 10 just add an "f" to one of the numbers: Random.Range(5f, 10)

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Thanks for pointing this out 😊

    • @TYNEPUNK
      @TYNEPUNK 2 ปีที่แล้ว

      thats interesting, Ive been doing it wrong all this time, what a very odd choice to exclude the last number. And also very interesting how adding f makes it include it, thats a new trick for me thanks. Also means everything I randomised in my games is slightly off :)

    • @Massive-3D
      @Massive-3D ปีที่แล้ว

      @@TYNEPUNK ew that sucks about the randomization, I never thought about it that way. Yikes!

    • @TYNEPUNK
      @TYNEPUNK ปีที่แล้ว

      @@Massive-3D im not even sure that he was right actually.

    • @deyama2012
      @deyama2012 ปีที่แล้ว

      @@TYNEPUNK well, if you read the docs, even the name of the second parameter is "maxInclusive" for float version and "maxExclusive" for intergers

  • @LightHermes
    @LightHermes 2 ปีที่แล้ว +3

    Awesome i love ragdoll effects

  • @castlecodersltd
    @castlecodersltd 2 ปีที่แล้ว +4

    Superb video, thanks for this. As someone who asked for it, I really appreciate you doing it. It would be great if you could do a video of a rag doll picking up another rag doll and throwing it.

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      Glad you liked the video 😊

    • @TYNEPUNK
      @TYNEPUNK 2 ปีที่แล้ว

      thanks for asking!

  • @ODESSARAMBO
    @ODESSARAMBO ปีที่แล้ว +4

    This is absolutely amazing tutorial! I do really appreciate the narration over the code. Well, I would probably love to see additional basic "high-level" introduction to a problem and a generic explanation of a solution. But even what you have right now is so useful and well put together. Thank you, keep up the good work!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for your feedback 😊

  • @newtounity7008
    @newtounity7008 2 ปีที่แล้ว +2

    Wonderful! I’ve long waited for this video to come out and here it is! Really appreciate it

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Great! Thanks for this 😊

  • @LlamAcademy
    @LlamAcademy 2 ปีที่แล้ว +3

    Super cool 😎!
    I couldn't figure out how to get the bone state at the start of the Animation so I assumed you had to do a fully procedural animation to achieve the stand up effect! This is a great, pretty cheap way to get a good looking stand up effect!
    Just projecting the stand up from face down... I guess you can do basically the same thing, but check the orientation of the hip (and maybe chest?) bone to see if it's facing world up or down. If they're on their chest, lerp to a the "get up from face down" animation, and if they're on their back, do the "get up from face up" animation that was just done here.
    Looking forward to the next installment and I'll definitely refer others to this video. Well explained and much cheaper (and easier!) than a fully procedural animation! Thank you!

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +4

      @LlamAcademy Thanks so much for this comment. Hopefully it can help some of your follower's "game dev dreams become a reality" 😊
      You're exactly right regarding the stand up from face down. Once you work out which way the character is facing you can then select a different animation and follow the same process.
      Loved the work you did on your AI series by the way. Keep up the good work😊

  • @Psychobun
    @Psychobun 10 หลายเดือนก่อน

    Thanks you! I was searching for a way to interpolate the dragdolls bones to the animation and this video has exactly what I wanted

  • @SvalandGame
    @SvalandGame ปีที่แล้ว

    One of the best Unity tutorials i've watched since 2016. Thank you very much for this

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks very much for this comment 😊

  • @etc5526
    @etc5526 2 ปีที่แล้ว +2

    I have planned to create a zombie game in future. Definitely this video might help me for that. Thank you so much! Keep it up😊

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      Thanks for this comment 😊

  • @TYNEPUNK
    @TYNEPUNK 2 ปีที่แล้ว

    Wow one of the best tutorials Ive found, thanks. I was trying to do this for 2 days!! Got the files from patreon, thanks!!

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      Thanks very much for your support 😊

    • @TYNEPUNK
      @TYNEPUNK 2 ปีที่แล้ว

      @@KetraGames thanks for yours too, saved me a ton of nightmares!!

  • @ArisChantzDev13
    @ArisChantzDev13 2 ปีที่แล้ว +6

    Great tutorial! The whole series has been amazing and every video you make well explained and to the point! Thank you!! Can't wait for the next topics you will cover!
    I think I found an issue though. If you shoot the zombie while the Stand Up animation is playing and not finished, when it tries to get up again the animation will continue from the frame that it got interrupted (at least that's what was happening in my case)
    I fixed it by writing at the ResettingBonesBehaviour function : _animator.Play(_standUpStateName, -1, 0f);

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Great spot. Thanks for sharing the solution 😊

  • @TYNEPUNK
    @TYNEPUNK 2 ปีที่แล้ว +1

    As for the flip, it looks ok, but of course you could simply check if it is facing down on its belly and use a get up from belly animation. That would be a quick fix. Very pro and awesome videos.

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Thanks, yes that's exactly what you could do to fix the flip 👍

  • @bixarrio5251
    @bixarrio5251 ปีที่แล้ว

    Nice video. I had a thing that used 3 different rigs for this, but this made it a little simpler. Just a note; In the method that gets the bone positions for the first frame, you pass in the array to store it in, but never use it.

  • @nolimit3281
    @nolimit3281 ปีที่แล้ว

    Some of the best tutorials I have ever found

    • @KetraGames
      @KetraGames  ปีที่แล้ว +1

      Thanks so much for this 😊

  • @user-uk9er5vw4c
    @user-uk9er5vw4c 9 หลายเดือนก่อน +1

    very good, this series is very well done!

    • @KetraGames
      @KetraGames  8 หลายเดือนก่อน

      Thanks for this 😊

  • @JacquesLetesson
    @JacquesLetesson ปีที่แล้ว

    Your tutorials have helped me tremendously. Thank you for these extremely well versed explanations.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Great to hear this, thank you 😊

  • @GameDevGarage
    @GameDevGarage ปีที่แล้ว

    Thanks for super clear explanation 👍This video found me just when I need it! Thanks Ketra!

    • @KetraGames
      @KetraGames  ปีที่แล้ว +1

      Glad it was useful 😊

  • @jinhuawen7876
    @jinhuawen7876 11 หลายเดือนก่อน

    This is absolutely amazing tutorial!!! Thank you so much!

  • @yvesevrard2421
    @yvesevrard2421 2 ปีที่แล้ว +1

    Thank you, your videos are very useful.

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Great to hear, thanks 😊

  • @lucashanscom2697
    @lucashanscom2697 2 ปีที่แล้ว

    Thank you!! Great and clear tutorial. Really appreciate the series.

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Brilliant, thank you 😊

  • @gmangman123
    @gmangman123 ปีที่แล้ว

    incredible tutorial! thx so much lady.

    • @KetraGames
      @KetraGames  ปีที่แล้ว +1

      Thanks, glad you found it useful 😊

  • @spyschannel8000
    @spyschannel8000 3 หลายเดือนก่อน

    Great tutorial!

  • @MarekNijaki
    @MarekNijaki 2 ปีที่แล้ว +1

    Awesome video!

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      Thanks for this comment 😊

  • @darashayda1
    @darashayda1 2 ปีที่แล้ว

    Terrific and clear, thank you

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Thanks for this comment 😊

  • @spider853
    @spider853 2 ปีที่แล้ว

    Just got to this channel, amazing tutorials! I have a tutorial suggestion if you would like to make. Basically having a running 3D character doing a 180 fast rotation (like in a sport game) and fixing the orientation after that, as the transform remains the same but the last frame of the turn around animation would look in another direction, so if running anim will be played it will look back at 180 which is wrong. Without interpolation would be easy as you just need to snap transform at 180 deg after turn animation ends, but with interpolation it gets tricky and I think a lot of people got this issue at some point

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      Thanks for the suggestion. Added to the list 😊

  • @mikailkotan5246
    @mikailkotan5246 ปีที่แล้ว

    Perfect , thanks

  • @inatesi
    @inatesi ปีที่แล้ว +1

    thank you!!!!

  • @Vjuh_and_kx
    @Vjuh_and_kx ปีที่แล้ว

    ОГО круто придумано! Спасибо большое за видео урок!

  • @RivenbladeS
    @RivenbladeS 6 หลายเดือนก่อน

    I would like to show us the directions and rotationmatches with some paint application end examples of what each offert doest what to the transform and rotation

  • @grzesfu
    @grzesfu 21 วันที่ผ่านมา

    I've been running a similar setup and run into several problems where other components (mostly animation rigging setup) is broken because the constraints store their relative offsets vs the first frame of the game which has the characters in the sampled get up animation state. So to avoid any future problems best to reset the character to its original position after a SampleAnimation call if you're doing it in Awake().

    • @KetraGames
      @KetraGames  17 วันที่ผ่านมา

      Thanks for sharing 😊

  • @MsWital
    @MsWital 2 ปีที่แล้ว

    It's very difficult, but very interesting!

  • @zendraw3468
    @zendraw3468 2 ปีที่แล้ว +3

    maybe if its face down just use a face down animation, also when will you make a discord server?

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +2

      Yes, a different animation would be needed for when it's face down. Then it's just a matter of choosing the right animation depending on how the character has fallen.
      We'll probably look into a Discord Server at some point, but focusing time on the channel content at the moment 😊

    • @PatrickNusbaum
      @PatrickNusbaum 2 ปีที่แล้ว

      @@KetraGames So I guess that when the zombie lands on a side, we'd also need a separate stand up animation for that, right?

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      @@PatrickNusbaum Yes, you could add stand up animations for the zombie on it's side if you want, or you may decide it looks acceptable flipping onto it's back or front when it's on it's side.

  • @darkhummy
    @darkhummy ปีที่แล้ว

    Was there ever a future video that covered how to handle different falling orientations? On it's back, on it's front etc? Watched the whole thing thinking that would be here D:

    • @darkhummy
      @darkhummy ปีที่แล้ว

      I was just curious if there was some clever way of implementing this. But to make do, I ended up just ray casting from my ragdolls hips, forward and backwards to check for anything in my "ground" layer mask and using that to determine if the ragdoll is face down or on its back. Works but feels kind of hacky. Definitely wouldn't use this approach with a more complex system with more than just "stand up from lying on back" and "stand up from facing down" animation states.

    • @KetraGames
      @KetraGames  ปีที่แล้ว +1

      Hi, not yet but it's coming soon 😊

    • @KetraGames
      @KetraGames  ปีที่แล้ว +2

      @Hummy rather than shooting a ray, you should be able to check the forward direction of the hips. Something like this - bool isFacingUp = _hipsBone.forward.y > 0;

    • @KD-tj6og
      @KD-tj6og ปีที่แล้ว

      @@KetraGames thanks for great tutorial. how soon will be the next ragdoll tutorial? Maybe you already know?

    • @KetraGames
      @KetraGames  ปีที่แล้ว +1

      Hi, we're working on the next Ragdoll video at the moment so it should be out by next week 😊

  • @supertenchoo4271
    @supertenchoo4271 ปีที่แล้ว

    I have a question I have Implemnt a ragdoll everything seem okay but after implementing Explosion force to character my character keep bouncing continuous to the floor what a fix suggestion please? I use mesh collider for my floor

  • @D.E.Nicolas.Goncalves
    @D.E.Nicolas.Goncalves 11 หลายเดือนก่อน

    Juice!

  • @spasmstudios
    @spasmstudios ปีที่แล้ว

    The transform of my npc isn't updating to the new position after becoming a ragdoll, as a result the character snaps back center of the test area rather than getting up from where it landed. Any idea what might cause this?
    Everything was replicated to a T, I even tested the code from the description and that didn't seem to fix it either. I'm assuming it has something to do with the AlignHipToPosition method.

    • @GatzeGalaxy
      @GatzeGalaxy 8 หลายเดือนก่อน

      You solved it? I have the same problem D:

  • @mico5637
    @mico5637 ปีที่แล้ว

    great tutorial! did you ever show how to fix when the enemy ragdolls face down?

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks. No, we've not published that video yet.

  • @alextreme98
    @alextreme98 ปีที่แล้ว

    At 23:36 is the rotation for offset or the position should be? Why you should multiply the rotation in order to find the position offset? I still have a lot of sliding, also when added the animation to stand up from facing the terrain, it has a weird 180deg rotation. :/

    • @KetraGames
      @KetraGames  ปีที่แล้ว +2

      Hi, the hip bone position we're using for the offset is the position of the hips if there was no rotation. Therefore we need to apply the rotation of the Zombie for the offset to be correct. For example, let's say that the hips are in position (0,0,1). If we then rotate the Zombie 90 degrees the hips will now be in the position by (1,0,0). Hope that makes some sense 😊

  • @jakubstaniszewski304
    @jakubstaniszewski304 ปีที่แล้ว

    What if hipsbone when performing animation is negative? It means that It can't raycast to the floor and its getting problematic

  • @kunz4164
    @kunz4164 2 ปีที่แล้ว

    Hey could you also show a tutorial where you create animation between a character and a object + character with another character. So something like The sims games, like hugging another character, picking up and reading a newspaper etc.

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Great idea, thanks. We'll add it to the list 😊

  • @jasonwilliams8730
    @jasonwilliams8730 2 ปีที่แล้ว +2

    👍

  • @cekconi1773
    @cekconi1773 2 ปีที่แล้ว +1

    👍👍👍

  • @supertenchoo4271
    @supertenchoo4271 ปีที่แล้ว

    I have question on this series why we take hitPoint.y after fire Physice dot raycast am wondering we take hitPoint dot y cos this point will be some point on enemy why we take it to make sure here is on the ground

  • @freeformcreations
    @freeformcreations 2 ปีที่แล้ว

    Hello Ketra, again terrific and astute presentation and much appreciated. Ketra we are running into an issue with your solution since our animated characters are exported from others, and this particular one we customized for Parkour there are really no per-bone collider. There is a master collider and that is it!
    Any idea how to apply your process to such animated characters?
    Thanx

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว

      Hi, have you tried the Ragdoll Wizard to generate the colliders and joints for each bone like in this video?
      th-cam.com/video/KuMe6Iz8pFI/w-d-xo.html

    • @freeformcreations
      @freeformcreations 2 ปีที่แล้ว

      I modified your code with a few lines , while your videos still remained valid, and I will post the code here:
      th-cam.com/video/KuMe6Iz8pFI/w-d-xo.html
      if you do not approve please delete, or write me and I will delete. Dara

  • @ДосталиЕвский
    @ДосталиЕвский ปีที่แล้ว

    Thanks for another wonderful tutorial. I have a problem, however. I get this error when doing ResettingBonesBehaviour(): "transform.localRotation assign attempt for 'mixamorig5:RightHandRing4' is not valid. Input rotation is { NaN, NaN, NaN, NaN }." What could be wrong?

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Hi, I'm not sure why that might be happening. Have you compared your script with the final version here - dotnetfiddle.net/v7ieoM.
      Also, check you have the state name and clip names correct in the Inspector. This needs to exactly match the spelling and case used in the Animator.
      Hope that helps 😊

    • @CarlosDTyrant
      @CarlosDTyrant ปีที่แล้ว

      Hi! Did you ever solve? I'm running into the same problem :(

    • @ДосталиЕвский
      @ДосталиЕвский ปีที่แล้ว

      @@CarlosDTyrant No I did not

    • @miroslavmiroslavov6327
      @miroslavmiroslavov6327 ปีที่แล้ว

      Try use Quaternion.Slerp instead of Quaternion.Lerp

    • @ДосталиЕвский
      @ДосталиЕвский ปีที่แล้ว

      @@miroslavmiroslavov6327 Did not help but anyway thank you for your response

  • @Werner-sv2le
    @Werner-sv2le ปีที่แล้ว

    Any more tutorials coming out soon??

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Yes, we've got plenty of tutorials in the pipeline 😊 We're planning to do another in the ragdoll series soon

  • @lordcabal
    @lordcabal ปีที่แล้ว

    Good tutorial, was exactly what I was looking for. I'm having an issue currently, when the zombie resets it's bones it resets them to a T-pose instead of the "standup" animation. I think I might've missed a step in the earlier video, because I've combed through this one and double-checked the code. Would appreciate any help!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Hi, the only thing I can think of is that the clip name you supply via the Inspector possibly doesn't match the name of the "standup" animation?

    • @lordcabal
      @lordcabal ปีที่แล้ว

      @@KetraGames No that wasn't the problem unfortunately. Here's a video to help visualize the issue: th-cam.com/video/Fv9QPoOxQBk/w-d-xo.html
      I've watched your other videos on root motion and such but I haven't been able to solve it. Maybe it's because the animator isn't enabled until after the bones have been lerped into the animation position? That would maybe explain why it goes back to the default t-pose. I'm stumped honestly.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Hi, it definitely looks like a problem when storing the bones of the animation. Somehow in this method
      private void PopulateAnimationStartBoneTransforms(string clipName, BoneTransform[] boneTransforms)
      {
      Vector3 positionBeforeSampling = transform.position;
      Quaternion rotationBeforeSampling = transform.rotation;
      foreach (AnimationClip clip in _animator.runtimeAnimatorController.animationClips)
      {
      if (clip.name == clipName)
      {
      clip.SampleAnimation(gameObject, 0);
      PopulateBoneTransforms(_standUpBoneTransforms);
      break;
      }
      }
      transform.position = positionBeforeSampling;
      transform.rotation = rotationBeforeSampling;
      }
      it is getting the T Pose bone positions rather than the start of the animation. Could you try a different animation to see if that makes any difference? Or possibly sample a different frame - clip.SampleAnimation(gameObject, 1)?
      If you haven't done so already, you can get the full script here to compare to yours - dotnetfiddle.net/v7ieoM
      Hope that helps 😊

    • @lordcabal
      @lordcabal ปีที่แล้ว +1

      @@KetraGames I managed to solve it. I originally had a parent object for the character where only the script and nav mesh agent were stored, separate from the animator.
      I thought I accounted for this in the code, as I was able to play animations and also get the correct name of the sampled clip, which I checked with " Print("" + clip.name); " in the animation clip bone storing method.
      But when I removed the parent object, transferring the script and nav mesh agent to the same object that had the animator, then rewrote some of the code to account for this it worked perfectly.
      Thanks for the help though! At first I was certain I missed a step somewhere due to my tendency to skip around tutorial videos, but it turned out to be my own decrepit way of making NPC's that was the root cause lol.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Glad you managed to fix it 😊

  • @etc5526
    @etc5526 2 ปีที่แล้ว +2

    Pls can you make a video for shooting mechanism and aiming animation tutorials?

    • @KetraGames
      @KetraGames  2 ปีที่แล้ว +1

      We'll add it to the list 😊

  • @fatihkartal1346
    @fatihkartal1346 ปีที่แล้ว +1

    you are so fucking good. i have been searching this fucking shit for a long time. :*

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      😂 Thank you 😊

  • @JustwaitNwatch-w
    @JustwaitNwatch-w 25 วันที่ผ่านมา

    transform.localRotation assign attempt for 'mixamorig9:RightHandThumb3' is not valid. Input rotation is { NaN, NaN, NaN, NaN }.
    UnityEngine.Transform:set_localRotation (UnityEngine.Quaternion)
    zombie:resetBonesBehaviour () (at Assets/script/ragdoll.cs:190)
    zombie:Update () (at Assets/script/ragdoll.cs:84)