Creating explosion that launches character body help

extends RigidBody3D
var speed = 10
var launchstrength=-1350
func _ready() -> void:
	linear_velocity = gamemanager.player.camera.global_transform.basis.z.normalized() *-1 *speed


func _on_ground_detection_body_entered(_body: Node3D) -> void:
	print("touched ground")
	$"push range/CollisionShape3D".set_deferred("disabled",false)
	queue_free()

func _on_push_range_body_entered(body: Node3D) -> void:
	if body.velocity!=null:
		body.velocity+=(global_position-body.global_position).normalized()*launchstrength

this is my code for what I want to be like a minecraft wind charge. For some reason, whatever the value of lanchstrength is, it’ll always launch the player down a bit.

The idea for the code is when it touches ground I want it to get a vector from the position of the node to whatever body is in side and add a force in that direction. If anybody has a solution to make the force apply to static bodies to that would be cool. Thanks in advanced to anybody who helps!

I’m not 100% sure what you want, tbh. You want to launch the player into the air, when he touched a certain object?

Anyway, the direction is given by the result of global_position-body.global_position, not the launchstrength. So if “body” is the character stepping on the object, you need ot inverse the vector by either making launchstrength positiv or calculating body.global_position - global_position.

I hope I understood the problem correctly.

I think the direction should be correct? global_position - body.global_position results in a vector from body to self, but launchstrength being negative inverts the direction. So in the end the direction should be from self to body (thus moving the body away from the explosion’s center).

I’m more confused about this part:

	$"push range/CollisionShape3D".set_deferred("disabled",false)
	queue_free()

This should enable the collision shape during the same idle frame its parent is getting deleted, which deletes all of its children as well. I don’t think that’s enough time for anything to get detected entering the shape?

I would try changing the push_range’s collision shape to be enabled from the beginning, and instead of using the body_entered signal just call the area’s get_overlapping_bodies() function once.

func _on_ground_detection_body_entered(_body: Node3D) -> void:
	print("touched ground")
	launch_overlapping_bodies()
	queue_free()

func launch_overlapping_bodies() -> void:
	var bodies := $"push range".get_overlapping_bodies()
	for body in bodies:
		if body.velocity!=null:
			body.velocity+=(global_position-body.global_position).normalized()*launchstrength

The thought is having a ground detector and when it sees ground it will make an explosion radius. Then it will launch things inside of there away from the center then the entire thing will be freed. I used to have a short timer before freeing it and this was after I tried that and it failed

Well, I don’t know what I did but it seems to be fixed.