Emitting an explosion(mesh), and giving it the inertia from a Character Controller

Godot Version


I am attempting to have my character controller emit an explosion when it fires a projectile. The explosion has a smoke animation, which I would like to inherit the inertia from the character controller, so that the smoke keeps moving in whatever direction the player was moving at the point they fired a projectile. The problem is, the explosion_instance is a mesh(not a rigidbody), so I can’t apply velocity in a simple way.

I have tried updating a global variable “global_velocity”(of the character) in the physics_process, and then applying that to the explosion_instance in it’s own function.

Also, in my emit_explosion function, I am parenting the explosion_instance to a childnode(explosion_point) of the character controller, which I assumed would at least bind its position to the character controller, and allow it to move with the character.

In all cases, I am unable to get the explosion_instance to move after it emits. Instead, the animation plays and it stays at the place i instance it.

Below is the structure of my explosion emission function. I have removed any attempt to move it or set its position. Any feedback is much appreciated, whether general ideas or actual code. Thanks!

func emit_explosion(explosion_point, _delta):
	var explosion_instance = explosion_scene.instantiate()
	#define instance to delete it later
	explosion_instance_to_delete = explosion_instance
	#check for existing instances
	print("explosion count: ", explosion_point.get_child_count())

	#access the AnimationPlayer node of the explosion instance
	var animation_player = explosion_instance.get_node("AnimationPlayer")
	if animation_player != null:
	# Start a timer to remove the explosion instance after a delay
	var explosion_timer = $explosion_Timer
#delete explosion instance after timeout
func _on_explosion_timer_timeout():
	#var _delta = get_process_delta_time()
	print("timer end")

Have you thought to use the particle system for this?

1 Like

Possibly, but I like the stylized explosion using a mesh with noise controlling it’s alpha. It seemed less expensive than particles too.

For clarity, my character controller calls emit_explosion() in it’s physics process. emit_explosion instances a mesh(which has an alpha animating it to look like a smoky explosion), not a rigidbody. I want the instanced mesh to inherit some of the character controllers velocity at the moment it is instanced. Or, pass the velocity to it somehow

nevermind my reply, i misread the rigidbody part

It really depends, iGPUs are pretty powerful these days, and the more lines it takes in gdscript to achieve, even a CPU particle would be better since it would run in native code.

Even so, you would need to either setup a shader material to displace your mesh. Or just setup a custom node3d? Class with a lerping movent process.

1 Like

Whoops! I made a mistake describe my scene. I am indeed using GPUParticles3D, but using just a mesh in ParticleProcess, so I assumed it could not have physics from the main scene.

1 Like

Wow, I can’t believe there’s just a property for Inherit Velocity in Process Material LOL

1 Like

K, I’m not clear on your setup but if you haven’t already started the particle shader process you could create a shader uniform that the rigidbody could set its velocity, before the particle is emitted.

(This should be possible but I haven’t played with particle shaders specifically.)

Edit you found something already