Тёмный

Unity Tutorial: How to trigger a ragdoll on impact using C# 

PixelWitch
Подписаться 1,1 тыс.
Просмотров 42 тыс.
50% 1

Brackeys' tutorial on how to MAKE a ragdoll: • RAGDOLL PHYSICS in Unity!
Did I make sense? I've only been digging into Unity for about a year, I'm a new-ish programmer teaching newer programmers here, so I don't know what I have to explain and what I don't. Feedback is appreciated.
Me: Makes a video complaining about tutorials that take longer than 6 minutes.
Also me: Makes a 16 minute tutorial

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 144   
@Seestral
@Seestral 2 года назад
thanks for the super useful tutorial! Also I've seen people in comments asking for force applying to the object when getting hit so here's my take on it.. For context, I use a gun on my FPS game, when my gun shoots, the enemy the ragdoll triggers. I personally get the transform.forward from my FPS camera to determine where the force should be applied relative to where i'm looking. (Also I have my camera as a child of an empty gameobject to keep track of its position). with all that mentioned I simply make a reference to the player camera using - [SerializeField] GameObject playerCam; - (and reference it from inspector) then inside EnableRagdoll() into Rigidbody foreach, I simply addforce to the rigidbodies using rigid.AddForce(playerCam.transform.forward * 200f, ForceMode.Impulse); Of course this function would have to be called into another function when you shoot the enemy so it triggers properly. this was my 30 second smart moment so I hope you enjoyed it (even though this is super basic...)
@PixelWitch
@PixelWitch 2 года назад
cool, I am pinning this so other people can find it, thanks for sharing how to do this!
@Derekstefan
@Derekstefan 5 дней назад
Excellent tutorial. Clear explanation. Despite the video being nearly 16 minutes long, it certainly felt shorter than that. This tutorial was exactly what I was looking for. Thank you.
@Bruce.B
@Bruce.B 2 года назад
I can't believe I discovered such a genius so late. I blame RU-vid. I have been searching for all the right terms for your videos, but they never showed up until today. Anyway, I seeing you haven't uploaded for the last 9 months worries me though. Please don't stop making these videos. They are just perfect! ♥
@PixelWitch
@PixelWitch 2 года назад
thanks :) I've just been busy with work so stopped for a bit.
@GlitchVR
@GlitchVR 3 года назад
THANK YOU SO MUCH! STRAIGHT TO THE POINT AND FEEL LIKE I'VE ACHIEVED SOMETHING TODAY! THANK YOU!
@jstra
@jstra 2 года назад
I'm pretty new to unity. When you were fleshing out getting the ragdoll parts you said about writing collider then adding [ ] "which means it's an array". THANK YOU. I've added those from so many tutorials and you are the first person who actually said what they mean.
@Xzarations
@Xzarations 3 года назад
I love the way you do tutorials! Hopefully you decide to do more in the future
@PixelWitch
@PixelWitch 3 года назад
thank you, I'm working on one now actually :)
@Xzarations
@Xzarations 3 года назад
@@PixelWitch Awesome! Can’t wait to see what comes of this channel!
@cbuckington2933
@cbuckington2933 3 года назад
Hey :) Just wanted to let you know that you have a really fun and charismatic way of explaining things on a rather base level! Great job and wonderful sense of humour :'D
@PixelWitch
@PixelWitch 3 года назад
Thank you so much! :) this is a very encouraging compliment 😊
@ayushgupta3994
@ayushgupta3994 Год назад
this is the exactly i was looking for from whole 5+ days lol subbed straight away❤❤
@mrpotato8196
@mrpotato8196 Год назад
This 1 video taught me 2 things- 1. what the title said 2. foreach function (I rarely work with arrays so I never really came across it lol)
@teknofis2604
@teknofis2604 3 года назад
I know its a simple topic but it's still is the best explanation I've ever seen about Ragdoll On/Off switch. Definitely an absolute hit for beginners. Pls keep teaching stuff :) Edit : Just looked at that simple drawing explanations again and .. You're a very good teacher :)
@gamesfordlegend
@gamesfordlegend Год назад
i love the way you explained everything at the beginning, nice video
@Arrzee.
@Arrzee. 9 месяцев назад
PLEASE DO MORE UNITY TUTORIALS! A good one to start with is a How to make an enemy attack using NavMesh tutorial! Many people need help with this ( I need help ) and it would a great tutorial
@ahmetalkanduran
@ahmetalkanduran 3 года назад
Best Unity tutorial i have ever seen. Pls continue tutorials!
@znamiyu
@znamiyu 2 года назад
Thanks ! Love the visual explanation, it's really good and on point.
@janpaweii3115
@janpaweii3115 Год назад
Thank you. Simple and effective. i enjoy following you coding because you have a nice clean structurized way and explaining everything great so its really easy to understand! Not only to follow. Thanks witch :D Greetings from a witcher
@liamlee8670
@liamlee8670 Год назад
Only 790 subs??? You are a godly coder, i cannot thank you enough. You dont know how important this is to my specific game.
@MrHughlio912
@MrHughlio912 6 месяцев назад
very straight forward, thanks for the help! by the way what's that groovy song playing at the end?
@Enzorojopasion
@Enzorojopasion Год назад
This video saved my ver existance, thank you very much queen, you just won yourself a new sub!!!!! Keep up the great work!!!!!
@LePeppino
@LePeppino Год назад
That was a fantastic explanation, really fun and easy to follow and working well. Don't sell yourself short, you did a great job! edit: oops, spoke too soon.. I have a little problem with the mainCollider of the character: when RagdollModeOn is called and the mainCollider gets disabled, it just stays in place while the rest of the body ragdolls properly, creating this stretchy looking glitch. Am I missing something? The mainCollider is applied to the character model itself, where also the rigidbody and the animator are.
@DaveSucker
@DaveSucker Год назад
thank you so much i'see many tutorials but this tutorial helped me a lot keep it up btw love your channel
@InfernalHedgehog
@InfernalHedgehog Год назад
This was probably the most useful tutorial I have ever seen. Thank you so much for making it!
@glowy6289
@glowy6289 2 года назад
at Void start when i typed in RagdollModeOff it says it doesnt exist in that context, why?
@PixelWitch
@PixelWitch 2 года назад
hmm, not sure, did you put the (); at the end? maybe it thinks you are are trying to use a variable that doesnt exist instead of a method. the (); tells it its a method
@glowy6289
@glowy6289 2 года назад
@@PixelWitch I have a () at the end
@F0atie
@F0atie 2 года назад
THANK YOU SOOOO MUCH DEFO 100% deserved th follow the tav helped so much with my ideas THANK YOUUUU
@linastreich4468
@linastreich4468 Год назад
Are you sent from god? Thats exactly what I needed to know, THANK YOU
@THEM0J0MAN
@THEM0J0MAN Год назад
Such a good, energetic, succinct tutorial. 👍
@SuperLitSawyer
@SuperLitSawyer 4 месяца назад
Can i have the script please? I'm working on a Sonic fangame called: Sonic the Hedgehog Blast/Sonic Hijinks/Sonic Test.
@SuperLitSawyer
@SuperLitSawyer 4 месяца назад
Please reply.
@yakwii800
@yakwii800 8 месяцев назад
A less complex way would be to take in a parameter like so public void TurnOn(bool on) { foreach (var col in Colliders) { col.enabled = on; } foreach (var ps in parts) { ps.isKinematic = !on; } animator.enabled = !on; }
@yakwii800
@yakwii800 8 месяцев назад
Also public void TurnOn(bool on, Vector3 force) { foreach (var col in Colliders) { col.enabled = on; } foreach (var ps in parts) { ps.isKinematic = !on; } if (on) { force.y = 15; parts[0].velocity= force; } animator.enabled = !on; } allows you to not only turn it on but add some "kick back"
@foolauto915
@foolauto915 2 года назад
that's the best tutorial i've ever seen , very visual and dynamic
@ACR995
@ACR995 2 года назад
It’s only working for me if the object colliding with the rag doll has a rigid body on it
@equiaux
@equiaux 10 месяцев назад
Easy to understand Thanks a lot!
@Stonk26
@Stonk26 6 месяцев назад
how do we do it in sfm...
@harddev9181
@harddev9181 4 месяца назад
can i get that scout model plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
@korypostma
@korypostma Год назад
At 4:05, I prefer my ragdolls to be rad!
@Arrzee.
@Arrzee. 6 месяцев назад
⚠️How do I do this but with a ray cast weapon⚠️
@tolgahangulsoy3273
@tolgahangulsoy3273 2 года назад
You are amazing :) Thank you so much. Very hopefull.
@d0c_dev
@d0c_dev 3 года назад
thank you!!, now i just have to figure out how make the nav mesh agent stop sliding when the they bump into each other
@PixelWitch
@PixelWitch 3 года назад
you can add a line to the ragdollModeOn method that turns off the nav mesh, I think it's a bool like navmesh.isStopped = true; if I remember right.
@Mrt-yj4tg
@Mrt-yj4tg Год назад
I think I am in love
@RidersUnite_
@RidersUnite_ 2 года назад
I Get: error CS1520: Merhod must have a return type
@MrCrolic
@MrCrolic 10 месяцев назад
all code) using System.Collections; using System.Collections.Generic; using UnityEngine; public class ragDollOn : MonoBehaviour { public BoxCollider MainCollider; public GameObject thisGuysRig; public Animator thisGuysAnimator; void Start() { GetRagdollBits(); RagdollModeOff(); } void Update() { if (Input.GetKey(KeyCode.F)) isOnRagdoll(); } Collider[] RagdollColiders; Rigidbody[] LimbsRigitbodies; void isOnRagdoll() { RagdollModeOn(); } void GetRagdollBits() { RagdollColiders = thisGuysRig.GetComponentsInChildren(); LimbsRigitbodies = thisGuysRig.GetComponentsInChildren(); } void RagdollModeOn() { foreach (Collider col in RagdollColiders) { col.enabled = true; } foreach (Rigidbody rb in LimbsRigitbodies) { rb.isKinematic = false; } thisGuysAnimator.enabled = false; MainCollider.enabled = false; GetComponent().isKinematic = true; } void RagdollModeOff() { foreach (Collider col in RagdollColiders) { col.enabled = false; } foreach (Rigidbody rb in LimbsRigitbodies) { rb.isKinematic = true; } thisGuysAnimator.enabled = true; MainCollider.enabled = true; GetComponent().isKinematic = false; } }
@MrCher666
@MrCher666 9 месяцев назад
U are well done, thanks❤
@zezooalzezoo5200
@zezooalzezoo5200 2 года назад
Great explanation , thanks
@flipthebird6355
@flipthebird6355 2 года назад
It's 5am, I started trying to make a working ragdoll at 12, I hate physics so much
@Eternal_Night17
@Eternal_Night17 7 месяцев назад
Hi, if my Character has a script which follows the player and if I shoot a bullet at him he turn in to a ragdoll, but how to disable the script after he turned in to a ragdoll?
@manutm4uu
@manutm4uu 2 года назад
Is it possible to send the ragdoll flying by adding force?
@PenginWG3254
@PenginWG3254 3 года назад
thx
@FC12CGaming
@FC12CGaming 3 года назад
why isn't the collision working
@pedropc5824
@pedropc5824 2 года назад
Very well explained
@486x
@486x 3 года назад
hei do you know how to change character move speed via c# made with game creator?
@FiyasCO.
@FiyasCO. 2 года назад
THANK YOU SO MUCH
@gamedevGod
@gamedevGod 2 года назад
Nice tutorial! Thank a lot
@Dehakuzo
@Dehakuzo 3 года назад
Hol' up, You can't tease us with exploding skeletons like that. Any good sources for gibbing models like the final 10 seconds? Edit: Played around a bit, I found removing character joints achieves the effect mechanically, but the model stretches. Is the skeleton naturally split, or is there some method to achieve seperation?
@PixelWitch
@PixelWitch 3 года назад
all I did to make the skeleton able to break was set the break tolerance of the joints very low, so they break easily. since he was already a skeleton, his model's bones break away nicely-- to make a fleshy boi do this, you would need a version of his model with the limbs separated into jibs, that you could swap to. I mean, the joints would still break for the fleshy boy, but he would just sort of stretch and distort oddly instead of falling apart if his model doesn't have separated pieces. like his bones would sort of stretch him as they tumble apart.
@Dehakuzo
@Dehakuzo 3 года назад
@@PixelWitch Oooh, I love the break away tip, thanks for the info on separation.
@alfalabs8449
@alfalabs8449 3 года назад
Awesome, what about untriggering it then?
@GlitchVR
@GlitchVR 3 года назад
thank you thank you thank you!
@zsolesz48g96
@zsolesz48g96 3 года назад
PLS make sfm tutorial i really like to see (i like your vids btw)
@PixelWitch
@PixelWitch 3 года назад
Thanks! if you just want SFM specific technical tips, I recommend this channel, he's done like a million tutorials ru-vid.com I don't have any SFM specific tricks to teach, BUT, if you just want me to talk about animation tips in general (that would apply to any software), I could do that :)
@zsolesz48g96
@zsolesz48g96 3 года назад
@@PixelWitchsorry for late responding but it would be a really good idea ;)
@ehsanakrami4365
@ehsanakrami4365 3 года назад
Awesome tutorial thanks i want to simulate bullet force in character part like head or hand how can i disable animation for selection part(Hand) and make rogdoll work selection part? can Combine rogdoll physic and animation Togader 50-50?
@PixelWitch
@PixelWitch 3 года назад
I'm not sure if that's possible, you could try using layer masks to isolate your animation to different parts, and then maybe switch the layers off (turn down their weight) using code--but I don't know for sure if it would work, that's just what I would try.
@AHEK8
@AHEK8 6 месяцев назад
Go just make your ragdoll character separate and instantiate on ragdoll 😊
@Bat_pann
@Bat_pann 3 года назад
Thanks Very Helpful .
@Never_gonna_give_you_up789
@Never_gonna_give_you_up789 2 года назад
how do i do the collider thing with my raycast bullets
@PixelWitch
@PixelWitch 2 года назад
Here's how I'm guessing that would go: you'd have the script that's on the gun (or whatever) that does the ray stuff, and then another script on the character that does the ragdoll, and these two scripts need to talk to each other. if you've not done that before, its pretty easy. You can "get component" on a game object to access it's script, and then you can call functions in that script. the general template for this is: GetComponent().FunctionName(); so in your gun script it would have a bit like: the ray detects that it hit the character, lets store that character game object in a variable called "character". then character.GetComponent().RagdollModeOn(). if the ray is hitting and returning other things, like it hits the floor or the wall, which don't have a ragdoll script on them, it might cause an error. so you might need to add a tag or if statement or something that first checks if it's the character before it tries to get the script. hope that makes sense :)
@Never_gonna_give_you_up789
@Never_gonna_give_you_up789 2 года назад
@@PixelWitch Ok thank you
@ultmatepotato
@ultmatepotato Год назад
poor scout lmao
@abhilashh3904
@abhilashh3904 3 года назад
your voice is awesome
@PixelWitch
@PixelWitch 3 года назад
thank you :)
@abhilashh3904
@abhilashh3904 3 года назад
@@PixelWitch i just keep listening to your voice, style.of speaking :) ❤️
@imgenuinelynotgreat
@imgenuinelynotgreat Год назад
scout!!!
@ikkyino
@ikkyino 2 года назад
+10 tutorial.
@Mikelica69
@Mikelica69 2 года назад
Great video wow!
@Hekayt_Hekma
@Hekayt_Hekma Год назад
you r amazing♥♥♥
@renman3000
@renman3000 Год назад
DOPE
@hifgghhgg2914
@hifgghhgg2914 3 года назад
Tnx this tutorial help me alot
@PixelWitch
@PixelWitch 3 года назад
glad to hear it!
@Mr.IN3V1T4BL3
@Mr.IN3V1T4BL3 3 года назад
Super asmr
@tyrussell3516
@tyrussell3516 3 года назад
thank you sm!
@zezooalzezoo5200
@zezooalzezoo5200 2 года назад
But next time try to make some variables private, and call them on Awake 👍
@miaan9374
@miaan9374 2 года назад
Thank you beautiful
@HatGuy294
@HatGuy294 7 месяцев назад
scoot tf2
@UsmanAli-eg2sl
@UsmanAli-eg2sl 2 года назад
chu chu chu chu at 3:23 . Thanks me late
@barbarusonline
@barbarusonline Год назад
hey kinda like the style of explaination with all the drawing stuff. Good for stupid people like me
@Youdiedagainhuh
@Youdiedagainhuh 2 года назад
Thank you very good straight forward tutorial!
@conceptfactory5604
@conceptfactory5604 3 года назад
Here when i deactivate RigidBody, CapsuleCollider and Animator the actor jumps like a explosion impact
@davesaccount311
@davesaccount311 3 года назад
Same issue
@GlitchVR
@GlitchVR 3 года назад
Can you please next show how to apply a force! So when they get hit they go flying! :D
@PixelWitch
@PixelWitch 3 года назад
I had a bit of trouble getting them to react to force too so I don't really know the answer yet. there are some forces you can add but I dont know how to use them well yet, I would recommend experimenting with collision.impulse docs.unity3d.com/ScriptReference/Collision-impulse.html or forceMode.impulse docs.unity3d.com/ScriptReference/ForceMode.Impulse.html Good luck :)
@geliyorum0673
@geliyorum0673 3 года назад
Try this after assigning a RigidBody: ToggleRagdoll(true); foreach(Rigidbody rb in ragdollBodies) { rb.AddExplosionForce(5f, transform.position, 5f, 1f, ForceMode.Impulse); }
@FarraBotiLoL
@FarraBotiLoL 3 года назад
void SetVelocity(Rigidbody rig) { Vector3 Vrig = rig.velocity; //Modify each axis Vrig.x = 0f; Vrig.y = 5f; Vrig.z = 0f; rig.velocity = Vrig; } Call this function inside the RagDollOn() -> foreach(rigidbody)
@GlitchVR
@GlitchVR 3 года назад
@@FarraBotiLoL thank you!
@necatron73
@necatron73 Год назад
I'm guessing u can use this in conjunction with a simple a.i follower script.
@ekekw930
@ekekw930 6 месяцев назад
At 11:47, how can I make sure those red animation "hint" boxes (not sure what the correct name is) are also moved with the model?
@lazikbro12
@lazikbro12 Год назад
nope it only works like that when it starts in turns into a ragdoll
@bigsmoke8344
@bigsmoke8344 Год назад
1:02 That's a rigidbody trust me😂😂😂
@raycoolsen7952
@raycoolsen7952 3 года назад
Very helpful tutorial, especially the drawing explaining the difference between the two modes is really cool. You could have simplified the C# script a bit by making only one function RagdollMode(bool enable) and then using the passed bool to switch everything off and on. Another interesting topic could be how to get the figures to stand up again after they have fallen over. Thanks for the explanation!
@PixelWitch
@PixelWitch 3 года назад
Thanks for the suggestion on how to do it better. I did try to make it one function, but I was struggling with how to make the animator turn off first if it's true and last if it's false if I used one function with a bool argument like that. How do you move that one animator.enabled around, based on the input?
@alexisbaliari
@alexisbaliari 2 года назад
Just what I needed. Excellent!
@23r4y83rs
@23r4y83rs 9 месяцев назад
THANK YOU SO MUCH
@JaminJelly2
@JaminJelly2 3 года назад
Very in depth and very understandable, great job!
@PixelWitch
@PixelWitch 3 года назад
thank you :) I am never sure when I am under or over explaining things, so I appreciate the feedback.
@Mr.IN3V1T4BL3
@Mr.IN3V1T4BL3 3 года назад
@@PixelWitch can u tell how can I stand up after rag doll.
@admiralkhan1099
@admiralkhan1099 3 года назад
Hi I am your new subscriber P I want to learn sfm can you plz plz teach me any discord link plz
@PixelWitch
@PixelWitch 3 года назад
Thanks for subscribing! I may make some animation tutorials here soon, but since that will take me awhile, I always recommend this channel for sfm tutorials, this guy has covered everything. ru-vid.com
@PixelWitch
@PixelWitch 3 года назад
discord.gg/PcCZbxdkNF this is my channel discord
@Jaydenbb5
@Jaydenbb5 Год назад
I know this video is old by internet standards but if you still read comments on this I could really use some help. I added this code to the starter assets 3rd person controller prefab, and it uses a character controller in the player armature section, which means that when the script tries to access the rigidbodies, it does so on the player armature and gets stuck because there isn't one there. I thought it would be a good idea to just add a rigidbody to it, and while it fixed that problem, it now makes the player spin clockwise uncontrollably. If you know how to fix this then I would really appreciate it
@mhze
@mhze Год назад
Brackeys tutorials but better! Thank you!
@NordicGamesLab
@NordicGamesLab 2 года назад
Thank you, really helpful
@knowingph5802
@knowingph5802 3 года назад
cute voice i love it
@ApexPredatorM82
@ApexPredatorM82 Год назад
Super cool tutorial and your awesome way of teaching love it
@MSSMikos
@MSSMikos Год назад
Great tutorial! Now you get new subscriber and i will follow your best programming explanation.
@k-6353
@k-6353 11 месяцев назад
Hi, great tutorial, would love to see you make one for procedurally animated character!
@Resul1445
@Resul1445 2 года назад
You have a really good explanation. Thank you for this beautiful tutorial.
@bluekadue
@bluekadue 2 года назад
hey could you share the script please . im bad at scripting and always make errors
@mrgonuts
@mrgonuts 2 года назад
thank you so much for your great tutorial you did a great job of explaining it
@MaxDolotboy
@MaxDolotboy Год назад
Source code ?
@foxfire941
@foxfire941 3 года назад
Хороший урок. Но у меня накопилось несколько вопросов: 1). Можно ли использовать много коллайдеров для этого скрипта(много, потому что на каждой части тела они будут расположены)? 2). Если персонаж после такого падает, как тогда реализовать его подъём и ПЛАВНОЕ переключение с функции Ragdoll на Animator? 3). Как реализовать сопротивление персонажа другому предмету? 4). Как настроить скрипт под силу удара о коллайдер? А в целом всё замечательно.
@Kooczsi
@Kooczsi Год назад
same dude
@penghasiluangdirumah8386
@penghasiluangdirumah8386 2 года назад
bro share you c#
@rufusmassey899
@rufusmassey899 2 года назад
really well made tutorial
@Boxply
@Boxply 3 года назад
You're amazing!
@PixelWitch
@PixelWitch 3 года назад
Thank you 😊
Далее
Active Ragdolls; What Are They And How They Work
9:41
С какого года вы со мной?
00:13
Просмотров 174 тыс.
Active Ragdolls in Unity
10:02
Просмотров 139 тыс.
Learning C# In A Week... Otherwise I Fail University
9:04
So I Made an UNFAIR Modpack...
27:35
Просмотров 76 тыс.
I remade MARIO KART but with RAGDOLLS
10:02
Просмотров 579 тыс.
RAGDOLL PHYSICS in Unity!
17:59
Просмотров 507 тыс.
20 Advanced Coding Tips For Big Unity Projects
22:23
Просмотров 186 тыс.
Triggering Ragdoll Physics (Unity Tutorial)
24:32
Просмотров 30 тыс.