Godot Version
4.5
Question
I just recently transitioned my 3D FPS project from version 4.2.2 to version 4.5 so that I could use Jolt Physics to improve performance. I have some RigidBody3D box objects that can be broken after taking some damage, which will then instantiate a destroyed box scene at the same position and queue_free().
The issue I’m having is that when destroying the boxes with the shotgun weapon, the boxes will queue_free but the destroyed box will show up at the origin of the scene. Other weapons like the pistol work just fine, so I assume it has something to do with multiple bullets hitting the object at the same time. It seems to be inconsistent, as sometimes they’re destroyed normally. I added a safeguard “Target_Broken” boolean to make sure the Break_Object( ) function code runs only once, which seems to be the case but doesn’t fix the issue.
I also noticed that if I switch back to the default 3D physics this issues goes away completely. I’m not familiar with how Jolt Physics is different from the default or what about it would cause this issue. Does Jolt somehow work differently when it comes to instantiating and setting the transform of objects?
Code for the breakable objects:
extends RigidBody3D
var Life = 50
@export_enum ("Stone","Wood","Metal","Flesh") var Substance: String = "Wood"
@export var Broken_Model:PackedScene
var Target_Broken := false
# Apply damage to move object based on where the object is hit
func Hit_Successful(Damage, _Direction:= Vector3.ZERO, _Position:= Vector3.ZERO):
var Hit_Position = _Position - get_global_transform().origin
Life -= Damage
print("Target Life: " + str(Life))
if Life <= 0 and !Target_Broken:
Target_Broken = true
Break_Object()
if _Direction != Vector3.ZERO:
# Push object in direction based on damage
apply_impulse((_Direction*Damage/5),Hit_Position)
# Spawn in broken model
func Break_Object():
var broken_model_inst:Node3D = Broken_Model.instantiate()
get_parent().add_child(broken_model_inst)
broken_model_inst.global_transform = self.global_transform
queue_free()
Video showcasing the problem I’m having:
Any help or advice would be appreciated. I can provide more info if needed or the source code itself.