Alright so I'm updating a system I wrote to emit particles under the player sprite (In an empty Node2D attached to the player), and after updating the code that was perfectly fine before, everything stopped working. I thought maybe I wrote the code wrong but I checked multiple references and I have it correct. And I know it's correct, because it works for my Dash ability perfectly as intended. But the code is nearly the same for every particle function and there's no typos of my knowledge, and yet it doesn't work for anything but the Dash.
I have tried numerous combinations of my code layout and even went into the particle scenes (Which are all lone CPU particles by the way) and checked if it was emitting at the start (Not the problem due to another particle starting with emission like the dash). I am usually able to find something I did wrong when writing the logic but this is something I cannot figure out, as I changed nothing but the emit statements and nothing is different between the several systems. The logic should work as it is unchanged, I just have no idea why it would work for specifically one system and not the rest.
Side Note, I have tried commenting out the dash emission and it does not emit without the line, so that cannot be the issue since the line is functional.
Side Note 2, I tried adding the extra lines of code that the Dash function specifically is missing (The rotate and position lines) and it still worked perfectly fine. Just wanted to add this to clear up any confusion.
Here's some snippets of code for the different systems:
Dash Function:
func Dash(delta):
if not is_on_floor() and not (is_on_ceiling() and gravity_switched):
pause_gravity = true
velocity.y = 0
velocity.x = direction * (speed * 1.5)
move_and_collide(velocity * delta)
$Sprite2D.rotate(rotato * 2)
if not particle_added:
var _particle = dash_Particle.instantiate()
$Particles.call_deferred("add_child", _particle)
particle_added = true
if not timer_called:
$DashTimer.start()
timer_called = true
Kill Function:
func Kill():
Dead = true
var _particle = death_Particle.instantiate()
_particle.position = global_position
_particle.rotation = global_rotation
_particle.emitting = true
$Particles.call_deferred("add_child", _particle)
queue_free()
DustCloud Function:
func JPEmit():
if can_emit:
var _particle = jump_Particle.instantiate()
if particle_rotation == 1:
_particle.position = $Markers/Left.global_position
_particle.rotation_degrees = 90
elif particle_rotation == 2:
_particle.position = $Markers/Right.global_position
_particle.rotation_degrees = -90
elif particle_rotation == 3:
_particle.position = $Markers/Up.global_position
_particle.rotation_degrees = 180
elif particle_rotation == 4:
_particle.position = $Markers/Down.global_position
_particle.rotation_degrees = 0
_particle.emitting = true
$Particles.call_deferred("add_child", _particle)
can_emit = false
If anybody is able to help me understand what went wrong where, that would be a huge help. Thank you for reading!
I found the problem! I had a script that always set the dash particles to the global position of the player every frame via a global script. However, everything else was using the global position of the particles node attached to the player instead of the level. Which is something that I did not know was node specific. I just went ahead and made the particle container a child of the level and it now works. It also fixes an issue that I realized would happen later on thanks to @SilicDev