Help with first game simple particle2d system please

Godot Version 3

I want an effect to appear in his place when a player dies. here is my code but it doesn’t work for some reason.

extends KinematicBody2D

var speed = 500
var acceleration = 800
var deceleration = 1000
var velocity = Vector2.ZERO
var axis = Vector2.ZERO
var rotation_speed = 500
var target_rotation = 0.0
var current_rotation = 0.0
var return_speed = 5
var MAX_ROTATION_DEGREE = 30
var death_effect_scene = preload(“res://Scenes/pop.tscn”)

func _ready():
self.connect(“area_entered”, self, “_on_Area2D_area_entered”)

func _physics_process(_delta):

axis.x = Input.get_action_strength("right")-Input.get_action_strength("left")
axis.y = Input.get_action_strength("down")-Input.get_action_strength("up")

axis = axis.normalized() * speed

velocity = velocity.linear_interpolate(axis, 0.025)

velocity = move_and_slide(velocity)

func _process(delta):

if Input.is_action_pressed("right"):
	target_rotation = deg2rad(MAX_ROTATION_DEGREE)
elif Input.is_action_pressed("left"):
	target_rotation = deg2rad(-MAX_ROTATION_DEGREE)
else:
	target_rotation = 0.0

current_rotation = lerp_angle(current_rotation, target_rotation, return_speed * delta)
rotation = current_rotation
rotation = clamp(rotation, -PI/8, PI/8)

func _on_Area2D_area_entered(area):
if area.is_in_group(“Bullet”):
die()
print(“bullet”)
if area.is_in_group(“Enemy”):
die()
print(“enemy”)

func die():
print(“you are dead”)
var pop = death_effect_scene.instance()
get_parent().add_child(pop)
pop.global_position = global_position
var particles = pop.get_node(“Particles2D”)
if particles:
particles.emitting = true
queue_free()

Do you know if this fails and returns null?

A better way would be to put the emitting true in the ready function of the pop scene so you don’t need to call it manually like this.

Can you please explain it in code? I dont understand very well.

func die():
  print(“you are dead”)
  var pop = death_effect_scene.instance()
  get_parent().add_child(pop)
  pop.global_position = global_position
  queue_free()
# pop scene
func _ready():
  $Particles2D.emmiting = true
1 Like

Thanks soo much,i will try soon.

i am getting error Invalid set index emitting … with value of type bool? how to fix it

1 Like

I think i made a typo

$Particles2D.emitting = true

Without function? Yes?

I dont know why but its not working even with this.

As far as I can tell your code is fine. The problem may be with the particle effect, or maybe the parent node you add child to changes some how?

1 Like

Yes,there was a problem in the particle it was one shoot and i was forgetting to emit it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.