Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Bárbara Gabriela |
I put an Area2D into the player called “hit_area”, inside it a CollisionShape2D, then plugged a function into the player script so that when the enemy touches the player it would appear another KinematicBody2D in this scene that follows the player, but as soon as I start the game the 2 KinematicBody2D appears without even touching the enemy. How can I fix it?
Here’s the code:
extends KinematicBody2D
var state = 1
const slimezinho = preload("res://scenes/slimes/slimezinho.tscn")
const mini_slimezinhoinho = preload("res://scenes/mini_slimezinhoinho.tscn")
func _ready():
pass
func _process(delta):
#multiply
if(state == 2):
var slime = slimezinho.instance()
get_parent().add_child(slime)
slime.set_position(get_node("spawn").get_global_position())
pass
if(state == 3):
var slime = mini_slimezinhoinho.instance()
get_parent().add_child(slime)
slime.set_position(get_node("spawn").get_global_position())
pass
pass
#change state
func _on_hit_area_body_entered(enemy):
state += 1
pass