Jump to content

Ragdoll and dismemberable limbs


tipforeveryone
 Share

Recommended Posts

After 1 week learning LUA Script in Leadweeks, with asistance from our mighty members (macklebee, Josh, Brutile), I have created a test ragdoll and a gun to shoot it. Ragdoll's limbs are dismemberable too. These are videos about my work smile.png

 

(this one has a better quality)

 

I feel so excited now. I want to go further... I mean How can I "attach" this ragdoll skeleton to my character Mesh?

 

I used Blender Export Addon for Leadwerks, after that I only got a .mdl file with out any bones in it. I created bones for my character in blender. I noticed that bones are still remain with exported FBX file but I don't know how to use those bones

 

Can anyone give me some suggestions about my question ? smile.png Just show me the right way. I will follow hehe. Thank you guys

 

==========================================

(Edited in 160222)

==========================================

This part is for members who want to refer my ragdoll code. I know these codes are not perfect and surely need more development. You are free to adjust my code. If you find out any better method to improve it, please reply in this topic. I know I am still new with LUA Script and game programming.

 

Here is the instructions:

  • Create a new Map then a Box for a ground.
  • Create a Pivot, place it right on top of the ground box, name it "Ragdoll spawner" or whatever you like. Attach "RagdollChest.lua" to this Pivot.

You can change any parameters of Ragdoll, everything will be auto adjusted to produce a desired ragdoll form in your map's scene.
  • Create a Camera then attach "CustomFPSPlayer.lua" to it, Drag above "Ragdoll spawner" into "Target ragdoll" and choose "fire sound" in Script tab.

You should change the default weapon model (around lines 46 - 48)
  • That is all !! Press F5 and have fun.

Control:

  • Left Mouse = Shoot
  • Right Mouse = Iron Sight
  • Middle Mouse = Reset Ragdoll
  • ADSW = Movement control
  • X = FreeBone Style1
  • C = FreeBone Style2 (default for bullet impact on ragdoll)

RagdollChest.lua

CustomFPSPlayer.lua

post-16833-0-98999500-1456157680_thumb.jpg

  • Upvote 2
Link to comment
Share on other sites

How did you get the ragdoll physics to work so well? I remember spending hours only to find out that the joints are super-elastic when I tried to do it.

 

Attaching isn't too difficult. All you do is get the model's children and set the position of each bone to the ragdoll's limbs (you don't have to parent all the bones though). One issue I remember having though is that sometimes the model will disappear because it's bounding box kind of gets messed. I don't remember how to fix that part, but one thing that can help a little is to reposition the mesh to the torso of the ragdoll and manipulate the bones there.

  • Upvote 2
Link to comment
Share on other sites

How did you get the ragdoll physics to work so well? I remember spending hours only to find out that the joints are super-elastic when I tried to do it.

 

Attaching isn't too difficult. All you do is get the model's children and set the position of each bone to the ragdoll's limbs (you don't have to parent all the bones though). One issue I remember having though is that sometimes the model will disappear because it's bounding box kind of gets messed. I don't remember how to fix that part, but one thing that can help a little is to reposition the mesh to the torso of the ragdoll and manipulate the bones there.

 

Thanks for your reply, nick.ace

 

You said exactly, those bones connection is so elastic. I spent a whole day to find out that too, It seems to be no solution, then I decided to live with this.

 

Created bones by Joint:Ball and Joint:Hinge will be ok if I leave it "free", I mean no picking or interaction after dropping all bones for free falling, set collision type of bones to "Debris". Otherwise, they will be pulled out like hell...

 

All of my ragdoll's bones were created by code (Model:Box()). You mean I need to cut my model's body parts into pieces (sperated legs, arms, hands, head, torso etc) then attach each of them to corresponding bone ?

  • Like 1
Link to comment
Share on other sites

You said exactly, those bones connection is so elastic. I spent a whole day to find out that too, It seems to be no solution, then I decided to live with this.

 

You don't need to live with this wink.png

It is possible to directly access the NewtonDynamics-Functions like so:

 

Joint* j;
j = (...)
NewtonJointSetStiffness(((NewtonDynamicsJoint*)j)->newtonjoint, 0.42);

will set the stiffness of the joint j to 0.42. Of course you will have to make j point to the joint you created previously, before calling the function.

 

 

EDIT:

Oops, just noticed, you are probably using LUA, as you wrote things like "Model:Box()". No idea, whether you can do something like this in LUA. sad.png

Edited by Ma-Shell
  • Upvote 1
Link to comment
Share on other sites

Mmm... will you share the code with us?.. happy.png

Yes of course, I edited my topic with a small instruction part smile.png Feel free to download my .lua files

 

I wonder if you can go through each child joint on a model and change it to that type, is that even possible?

I will give it a try :D

 

Oops, just noticed, you are probably using LUA, as you wrote things like "Model:Box()". No idea, whether you can do something like this in LUA. sad.png

Thanks for your reply!

It is ok rolleyes.gif I have lived with that 1 weeks anyway, hehe.

Link to comment
Share on other sites

Sorry, I forgot you are doing dismemberment. If you were just doing a normal ragdoll, I'd say you could keep the mesh as one whole. If you are dismemberment, then I don't really know the best way.

 

Still waiting on that Lua support though.

 

Yes, I want a violent gameplay muahahha... Then I think I will find out how to do that smile.png

But, can you give me more instruction about attaching my bones to mesh? maybe a function in API Library which I did not notice or a small step by step tutorial, links, anything...

 

Thank you wink.png

Link to comment
Share on other sites

Yeah sure. You need to call FindChild() from your mesh, and that function takes in a string where you can specify a bone. This bone is an entity, so you can call SetPosition() and SetRotation() on it to the position and rotation of the joints of the ragdoll (GetPosition() and GetRotation()). Make sure you set the global flag to true though. You should be all set with this, but it'll end up being a lot of copy/pasting code since you have to do this with each joint.

  • Upvote 1
Link to comment
Share on other sites

Yeah sure. You need to call FindChild() from your mesh, and that function takes in a string where you can specify a bone. This bone is an entity, so you can call SetPosition() and SetRotation() on it to the position and rotation of the joints of the ragdoll (GetPosition() and GetRotation()). Make sure you set the global flag to true though. You should be all set with this, but it'll end up being a lot of copy/pasting code since you have to do this with each joint.

I feel a bit confused now. It will be nice to use FindChild() but I have some problems with my exported mesh. It was made in Blender and exported by "Exporter for Leadwerks" addon to .mdl and .mat files.

I open Leadwerks Model editor and find out that all of my character's bones were removed. So here are my questions

 

1. If I use Addon to export from Blender, is it possible to attach my ragdoll bone to the exported mesh (with no bones from Blender) ?

2. If I export to .FBX, yes, all of original bones are still there, showed in Leadwerks's model editor, do I need to "recode" them? And my model's skinning is still operational ?

Link to comment
Share on other sites

Yes, you would need an animated (or at the very least rigged) mesh. I static mesh isn't going to be very useful for this.

 

You don't need to recode anything. You just need to call FindChild() to get a reference of them in code and set the position and rotation of each of them to the corresponding ragdoll you made in the video. The model will still be allowed to animate, you just need to not set set the position or rotation while it's doing this.

  • Upvote 1
Link to comment
Share on other sites

Yes, you would need an animated (or at the very least rigged) mesh. I static mesh isn't going to be very useful for this.

 

You don't need to recode anything. You just need to call FindChild() to get a reference of them in code and set the position and rotation of each of them to the corresponding ragdoll you made in the video. The model will still be allowed to animate, you just need to not set set the position or rotation while it's doing this.

 

1 week passed and finally, I have done this "Bones and Mesh"

Here it is, the combination of mesh's original bones from blender and my own bones system, they work with eachother perfectly.

 

 

I find out how to dismember character's limbs too. WIP thank you so much nick.ace!!

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...