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()