But the player it is a Kinematicbody2D
The character does not move down and up.
Kinematicbody2D can still take a custom signal.
WHICH?
It would be easier to add joystick support to his code than the state machine you have now which is still showing an error on idle. Are you sure you want to do it that way? I think he shows how to use a signal in the tutorial.
Yes I want to put a joystick. But in the tutorial is with a Area2D.
I'll put it in simple terms.
Add a custom signal to the mob, ie signal hit
.
Then, connect the area2D's signal on body entered(body) from the signals list in the Area2D to the mob.
Then go into the mob code. In there, there will be a new function on_Area2D_body_entered(body). Under that, type emit_signal("hit").
Then, go to the main scene, and add a mob to it. Connect the mob's signal hit to the player in the inspector. After that, you can add your function to have the player defeated.
Now that it is done, you no longer need the mob in the scene, so it will be safe to delete it. Mobs will spawn with the signal connected to them.
How can I put a custom signal?
You should be able to add an area2d to the kinematic body. Kinematic bodies act with physics and need forces applied for motion.
Add signal hit before func _ready, like a variable.
- Edited
@fire7side said: You should be able to add an area2d to the kinematic body. Kinematic bodies act with physics and need forces applied for motion.
But I change the type?
Nope. Attach it as a child of the player, and do the same to it as I suggested for the mob.
Where it is the signal hit?
No, you have to type it above func _ready.
It gives me this error?
In a function, declare emit_signal("hit")
. Doing so will remove the error.
Where it is?
Did you type emit_signal("hit") anywhere? That will make the signal appear.
I put but not appear.
It's not in a function. If it was in, say, func _ready, it will appear.