-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Add ability to apply forces and impulses to SoftBody3D
#100463
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
Add ability to apply forces and impulses to SoftBody3D
#100463
Conversation
It's fine, right? If I add it to jolt and godotphysics in the same PR. Edit: I'm just going to do it, I think it's fine. |
The Softbody class didn't have apply_force method, so I have to make it myself. I don't really know how force works. So I just tried stealing it from the GodotBody3D. Also, assuming that the |
SoftBody3D::apply_impulse()
and SoftBody3D::apply_force()
Most of the code from the |
What I made with it so far: softbody.controller.mp4 |
Next, I'm working on adding apply_force() to jolt, but I can't figure out how to do that. If there's smart people out there want to give suggestions, you are welcome to. Edit: Or just, @mihe HELP! |
SoftBody3D::apply_impulse()
and SoftBody3D::apply_force()
SoftBody3D::apply_impulse()
and SoftBody3D::apply_force()
I think I figure it out, from comparing jolt with godot physics' What I understand is, Jolt softbody don't have the functionality to apply force. So I think I have to add the functionality to the |
Added apply_force to jolt, but not sure if it behaves properly. Also, I just found out that sometimes when running the scene, the softbody just disappear. IDK how that happened. |
Added apply_central_force and apply_central_impulse to jolt and godot. The way it works is just applying the force/impulse to all vertices, but the force/impulse is divided by the vertices count. |
These are how the functions compared to rigidbody. The impulses have a strength of 0.2. Jolt physics: softbody.jolt.mp4Godot physics: softbody.godot.mp4 |
It's ready to review! |
5962e89
to
beb2413
Compare
thirdparty/jolt_physics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp
Outdated
Show resolved
Hide resolved
Looks good to me! One nitpick would be to update all of Jolt to 248253f88a5945c2032ffb397101afb9f88aeca5 or higher. I didn't initially suggest this because I knew there was another PR in progress that was touching the same files. But a full integrate can happen another time too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes look good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (rebased on top of master
c3ae6aa), it works as expected when using GodotPhysics3D. However, when using Jolt Physics, nothing happens when trying to set an impulse (on a single point or all points).
Testing project: test_pr_100463.zip
Press R to apply an upwards impulse on a single point (and all points) at the same time.
I tested it. It does work, but need a very large force for it to work. Apparently, in jolt physics, the more vertices added, the greater the force needed (for apply impulse and force).
Edit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some very minor cosmetic issues, but looks good to me otherwise.
52a252f
to
e2df211
Compare
6e3ceb3
to
fe3aaa2
Compare
Thanks! Congratulations on your first merged contribution! 🎉 |
Closes godotengine/godot-proposals#1013
The goal of this PR is to add
apply_impulse
andapply_force
to theSoftbody
nodeAdding them to the
GodotPhysics
andJoltPhysics
.Added functions
Softbody3D:
void apply_central_force(force: Vector3)
void apply_force(force: Vector3, point_index: int)
void apply_central_impulse(impulse: Vector3)
void apply_impulse(impulse: Vector3, point_index: int)
PhysicsServer3D:
void soft_body_apply_central_force(body: RID, force: Vector3)
void soft_body_apply_central_impulse(body: RID, impulse: Vector3)
void soft_body_apply_point_force(body: RID, force: Vector3, point_index: int)
void soft_body_apply_point_impulse(body: RID, impulse: Vector3, point_index: int)
Built-in documentation
Edit: I think these are a bit outdated
Show documentation
PhysicsServer3D
SoftBody3D
Demo
Demo project: godot-softbody-apply-force-and-impulse-test.zip
These are how the functions compared to rigidbody.
The impulses have a strength of 0.2.
The forces have a strength of 15.
Jolt physics:
Jolt.SoftBody.mp4
Godot physics:
Godot.SoftBody.mp4
Player Controller (Jolt physics):
softbody.controller.mp4
Implementation Details
Godot apply_impulse
GodotSoftbody3D
already haveapply_node_impulse
method which apply impulse to a vertex. So I just use that for thesoftbody.apply_impulse
.Godot apply_force
GodotSoftbody3D
havevertex.f
which stores the applied forces, and it will handle it somewhere. Therefore, I only need to add a method that add the forces to it.Jolt apply_impulse
JoltSoftbody3D
didn't have a method to apply impulse. So I addedJoltSoftBody3D::apply_node_impulse
. It works like theGodotSoftBody3D::apply_node_impulse
which just addimpulse * vertex.inverse_mass
to the vertex velocity.Jolt apply_force
[Outdated]
I notice that the core JoltPhysics didn't have a way to apply force to softbody vertex. Hence, I have to add that functionality into the core of the JoltPhysics engine.
I added
vertex.mForce
, which store the forces that are going to be applied. Then applies it in theSoftBodyMotionProperties::IntegratePositions
and reset the force onSoftBodyMotionProperties::UpdateSoftBodyState
.apply_central_impulse/force
For
SoftBody.apply_central_impulse
andSoftBody.apply_central_force
I addedapply_central_impulse
andapply_central_force
methods to jolt and godot. It works like theapply_node_impulse/force
but the impulse/force is divided by the vertex count and applies it to all vertices.