-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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 SoftBody3D::apply_impulse()
and SoftBody3D::apply_force()
#100463
base: master
Are you sure you want to change the base?
Add SoftBody3D::apply_impulse()
and SoftBody3D::apply_force()
#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. |
I've never done full integration before, because of that, I don't know how to do it. So let's just do full integration another time. :D |
Now, can someone else review it, merge it, or whatever to do next. |
08bf583
to
ba422d7
Compare
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
Show documentation
PhysicsServer3D
SoftBody3D
Demo
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
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.