Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ragdoll - Physical bone node #11973

Merged
merged 1 commit into from
May 7, 2018
Merged

Conversation

AndreaCatania
Copy link
Contributor

I've implemented new node "Physical bone" that has the function to simulate ragdoll.

This new node is a physical node and like all physics nodes must have a shape, and can usa a Joint.

The particularity of this node is that when it's attached to a skeleton bone it'll copy its position to the bone skeleton.

Here a video that show that node in action: https://youtu.be/1pPmBq10TV8

Physical skeleton structure

As you can see each bone has one (or more) shape that represent the bone collision, and a joint that is used to tie the bone with its parent bone.

untitled2

Each Physics Bone must be child of its parent bone and only the first bone must be child of skeleton.
Maintain this structure is necessary to be sure to use the inverse kinematic solver (that will be implemented)
(of course the first bone must be joint free)

I've also created a function that automatically create the physics skeleton, the only problem with this function is that it'll create a Physical Bone for each bone in the skeleton and this is not the best thing to do for performance reason. Its main objective is to give to the artist / developer a quick understanding of how to create a physics skeleton structure.
untitled

Function

By default physics simulation is stopped. You can start/stop it by using the skeleton function:
void physical_bones_simulation(bool start); that active the simulation to all physics bone attached. Otherwise you can active bone simulation one by one by using the PhysicalBone function void set_simulate_physics(bool p_simulate);

Other two utility function in skeleton are:

void physical_bones_add_collision_exception(RID p_exception);
void physical_bones_remove_collision_exception(RID p_exception);

Use these to set the parent collision body as exception

Known issue:

If you scale the skeleton in some way the shape size remain unscaled, this is fixed by bullet implementation that allow physics body scaling.

N.B.

This video was taken using Godot physics. This mean that this implementation is not Bullet dependent.

@reduz
Copy link
Member

reduz commented Oct 9, 2017 via email

@AndreaCatania
Copy link
Contributor Author

Initially I had developed it in a way were all physical bones were all childs of skeleton. I changed it as you see now, after the conversation with you where you told me that we need a way to iterate over each bone and find its joint in order to calculate inverse kinematic.

If I had leaved all bones as childs of skeleton I was needed a way to map all physical bones in order to find the correct parent bone during inverse kinematic calculation

So I thought that the best solution was to create this hierarchy directly in the editor; so is easy find a parent and process inverse kinematic.
Another benefit (that I noticed during the implementattion) is the order, in this moment manage these nodes is very easy even with a lot of nodes.

However the physical bone is set as toplevel node so there shouldn't be any difference in the performance.

Probably your concern is the creation of these bones, and I can reassure you it's tedius in both way :D. So I'm thinking about a way to create these bone easily.

For example implement a dedicated menu to create bones automatically, by the selection of initial bone and final bone so the system can calculate the shape and joint. But I just need some time to do that.

@reduz
Copy link
Member

reduz commented Oct 9, 2017 via email

@SaracenOne
Copy link
Member

Looks interesting. This is actually very similar to a system I prototyped with scripts, but of course more tightly integrated.

@SaracenOne
Copy link
Member

Can it also do partial ragdolls like my system does, where some bones are controlled by the animation system while others are simulated by physics?

@SirPigeonz
Copy link
Contributor

SirPigeonz commented Oct 11, 2017

@AndreaCatania
WOW glorious stuff! :D

I have simmilar question to @SaracenOne 's.
Additionally. Is it possible to blend by weight pose made by physics and animation? So "active ragdolls" would be possible?

I would also make collision exception as PhysicsBone property. It works similar in UE4 PhysicsAsset (ragdoll) editor.

PS
Building is broken :)

@AndreaCatania
Copy link
Contributor Author

AndreaCatania commented Oct 11, 2017

@reduz I've implemented some functions that allow to have any type of hierarchy in the editor since now the hierarchy is managed internally.

I've added this function PhysicalBone *get_physical_bone_parent(int p_bone); into skeleton in order to find parent physical bone and resolve inverse kinematic.

@SaracenOne, @n-pigeon

I have simmilar question to @SaracenOne 's.
Additionally. Is it possible to blend by weight pose made by physics and animation? So "active ragdolls" would be possible?

I'm not sure what you mean with "blend by weight pose" but yes, it's possible have animation and physics at same time. To improve this aspect I've also added some function.

Here a video that show how it works (the last part could be a bit strange but it demonstrate how static body parameter works) https://youtu.be/GA2X5BcL2ZM.

In this video you can see that I can start the physics simulation in any time of animation.

I'm glad that you enjoy it!! :)

@SirPigeonz
Copy link
Contributor

SirPigeonz commented Oct 12, 2017

@AndreaCatania
Very cool! :D
I will rephrase my question (sorry for my English, it sometimes "borks" xD ).
Is it possible to blend anim-pose and physics-pose using weights? Something like use 0.4 physics and 0.6 animation?

This is really cool stuff for me :D Can't wait to use it. Maybe I will have some time tonight, to play with your branch :D

@AndreaCatania
Copy link
Contributor Author

In teory it is possible, but it'll apply other layer of calculation and the physics effect could not be so real or good... So I don't know if it's good.

Probably what you need to use is the relaxation parameter that is present in some joints (like: Hinge, Cone, etc..) in this way you are able to create a ragdoll more controllated because the joints are more elastic.

I've to insert some parameters in the physical bone, like the mass friction, etc.. I'll look also for this.

However can you tell me an engine that does this blending so I can see its effect?

@slapin
Copy link
Contributor

slapin commented Oct 12, 2017 via email

@AndreaCatania
Copy link
Contributor Author

So we are talking about muscle simulation like "Euphoria engine" does. https://www.youtube.com/watch?v=87qdmuOesRs

This is not a pure ragdoll system

@AndreaCatania
Copy link
Contributor Author

This video is too funny: https://www.youtube.com/watch?v=QjGc2XBIEgQ
euphoria engine in GTA 4 vs (probably Rockstar game ragdoll system) in GTA 5

@reduz
Copy link
Member

reduz commented Oct 12, 2017 via email

@AndreaCatania
Copy link
Contributor Author

I inserted the icon, included missing physics parameters, and I had rebased it to 1 commit. Let me know if there's something missing or that must be improved.

@SirPigeonz
Copy link
Contributor

SirPigeonz commented Oct 12, 2017

@AndreaCatania
Blending partially pose from physics and animation is very common and simple technique actually. It helps making ragdoll less rag-like :) https://youtu.be/zVWZbxGFGiA?t=31

Although maybe this would be better to control from future 3.x animation system using blends. I was just curious if it is already possible. :)

@AndreaCatania
Copy link
Contributor Author

@n-pigeon yes I agree with you "active ragdoll" is way better than pure physics ragdoll.

However I don't know if it's just an animation blending... I want investigate more about it...

@slapin
Copy link
Contributor

slapin commented Oct 13, 2017 via email

@SirPigeonz
Copy link
Contributor

SirPigeonz commented Oct 13, 2017

@AndreaCatania
Sure, I just wanted to clarify myself :3

@slapin
Animation systems are task for 3.1 @reduz investigates it recently. They are probably out of scope of this PR. :) But I know what you mean they will have to communicate at some point when anim system will be ready.

@reduz
Copy link
Member

reduz commented Nov 3, 2017

Code looks good for the most part, but as I mentioned, I'am against using regular joints for this.
I think joints should also exist within the PhysicalBone node and be constrained to what they are used for in IK (which is generally hinge and cone twist).


PhysicalBone();
~PhysicalBone();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While not generally using joints if you want with this, these bones should include the same information that will be used for IK. This is, an option between:

  • Joint Disabled
  • A Regular pin
  • A Cone twist
  • A Hinge

and relevant options. The joint would be created by this bone and attachment between it and the parent bone, as well as collision exception, would be handled in this class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also need an offset from the center of mass.

@akien-mga akien-mga modified the milestones: 3.0, 3.1 Nov 22, 2017
@AndreaCatania
Copy link
Contributor Author

Here a video to show how ragdoll looks like now: https://youtu.be/6TyRFk6dpU4

@SirPigeonz
Copy link
Contributor

Awesome work! I understand joint settings are placed in PhysBone Node?

Unreal4 allows to test ragdoll in viewport in various useful ways.
You can grab it and then move like rag or poke with your mouse applying small burst of force. You can test it with gravity or without it.

@AndreaCatania
Copy link
Contributor Author

I understand joint settings are placed in PhysBone Node?

Yep it is inside physical bone

Unreal4 allows to test ragdoll in viewport in various useful ways.
You can grab it and then move like rag or poke with your mouse applying small burst of force. You can test it with gravity or without it.

It's very useful to test it inside editor, and it's easy to make even in Godot, But I prefer as first thing that it is merged

Implementing ragdoll

Implementing ragdoll

Implementing ragdoll

Implementing ragdoll

Implementing ragdoll

a

Implemented implicit hierarchy.

Improved

Added some physics properties

Added bone offset to preserve COM, partially fixed scaling

work in progress

WIP

wip

Implemented Joint Gizmos

Implemented pin joint joint

Implemented all joints
@AndreaCatania
Copy link
Contributor Author

Rebased

@blurymind
Copy link

blurymind commented May 10, 2018

@AndreaCatania Can this be used to set up jiggle bones like this addon does so greatly
https://github.com/Bauxitedev/godot-jigglebones
Also how complicated would it be to replicate the addon's functionality?

Video/example project would be awesome! 👍

@AndreaCatania
Copy link
Contributor Author

@blurymind Right now without any addition you can achieve this result: https://youtu.be/p1eDWQaqoZE

Basically what is required to do to get the same result is implement active ragdoll that is something that I've to work on after the merging of IK

@slapin
Copy link
Contributor

slapin commented May 10, 2018 via email

@AndreaCatania
Copy link
Contributor Author

@slapin with ragdoll you can do it right now, you don't need (and you don't have to do) create a bone for each bone of the skeleton (for example you don't need to add all 10-30 bones of the hand to have a good ragdoll of a character).

I'll write an article about it, to explain how it works.

For IK in this moment all bones of chain participate to the solving. But I prefer to talk about it here: #18699. For example why do you need to keep a particular bone rigid?

@twilson90
Copy link

@AndreaCatania I tried using PhysicalBones from the latest possible build earlier (with Skeleton -> Create physical skeleton) and couldn't get it to work.
I tried making the root node a RigidBody and a KinematicBody but I get a node warning saying it has no collision shapes, even though the skele with physical bones is inside.
Also I've noticed that 'Simulate physics' and 'Static body' are not present in the PhysicalBone properties like they are in the video.

@AndreaCatania
Copy link
Contributor Author

@hedgehog90 You don't need to add a physical body to the root. I'll write a short article to show how it works.
Also I've removed Simulate physics and StaticBody from the PhysicalBone because it make a bit of confusion, To active the physics simulation you have call physical_bones_start_simulation in the skeleton

@AndreaCatania
Copy link
Contributor Author

I've written the article that explain ragdolls, you can find it here: https://godotengine.org/article/godot-ragdoll-system

@twilson90
Copy link

The last few 3.1 builds I've tried getting this to work but it completely spazzes out.
From the latest build (yesterday):

godot ragdoll arms

I've tried it on the simplest skeletons and the results are all the same

@AndreaCatania
Copy link
Contributor Author

@hedgehog90 don't forget to apply the last section of article "Collision Layer and Mask" Let me know if you fix it.

@twilson90
Copy link

OK, I've realised that deleting ancestral physical bones causes their children to go nutty, or detach completely, falling to the floor and not moving with the character.
But even after fixing that and potential problems with the collision layers, the robot is still acting a bit wild.
I've got a much simpler example, where I've tried to implement a fat bendy sausage (!!) with psychical bones with pin joints but check out what happens (I'm not applying any forces)

sausage trouble

Similarly, the robot character does not act like it does in your example. His arms don't flail quite so wildly anymore but they never stop moving.
If I simulate all the bones, the body doesn't crumple to the floor in quite the same way either.
Unless someone can confirm otherwise, I think something's different in my build of Godot to yours.

Perhaps you could upload the modified Platformer 3D project and I could try compiling it?

@AndreaCatania
Copy link
Contributor Author

@hedgehog90 can you please open an issue with this example project attached on and mention me? So I can verify what's the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.