Skip to content

Commit c529f36

Browse files
committed
Jolt physics: Setting position instead of velocity in JoltSoftBody3D::set_vertex_position
This fixes a discrepancy between godot physics and Jolt physics where in Jolt a vertex pinned to a body only gets its velocity updated while in godot it gets its position updated. This causes it to lag one frame behind. Fixes godotengine#106301
1 parent 209a446 commit c529f36

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

modules/jolt_physics/objects/jolt_soft_body_3d.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,21 +630,12 @@ void JoltSoftBody3D::set_vertex_position(int p_index, const Vector3 &p_position)
630630
ERR_FAIL_INDEX(p_index, (int)shared->mesh_to_physics.size());
631631
const size_t physics_index = (size_t)shared->mesh_to_physics[p_index];
632632

633-
const float last_step = space->get_last_step();
634-
if (unlikely(last_step == 0.0f)) {
635-
return;
636-
}
637-
638633
JPH::SoftBodyMotionProperties &motion_properties = static_cast<JPH::SoftBodyMotionProperties &>(*jolt_body->GetMotionPropertiesUnchecked());
639634
JPH::Array<JPH::SoftBodyVertex> &physics_vertices = motion_properties.GetVertices();
640635
JPH::SoftBodyVertex &physics_vertex = physics_vertices[physics_index];
641636

642637
const JPH::RVec3 center_of_mass = jolt_body->GetCenterOfMassPosition();
643-
const JPH::Vec3 local_position = JPH::Vec3(to_jolt_r(p_position) - center_of_mass);
644-
const JPH::Vec3 displacement = local_position - physics_vertex.mPosition;
645-
const JPH::Vec3 velocity = displacement / last_step;
646-
647-
physics_vertex.mVelocity = velocity;
638+
physics_vertex.mPosition = JPH::Vec3(to_jolt_r(p_position) - center_of_mass);
648639

649640
_vertices_changed();
650641
}

0 commit comments

Comments
 (0)