0 votes

Hi ! I'm having an issue...
I try to make my player kill an enemy if it enters the enemy's zone and press space bar, input named "kill". the player can kill the enemy only if it's the same "type". Everything works before I code to make the player kill the enemy only if the player hot the kill input.

Here is my code without the need of an input:

func onenemywhitecheck() -> void:
if type == 0 :
emit_signal("kill")
score += score
Here, everything works perfectly. the enemy dies and the score rises.

Here is my code with the need of an input:
func onenemywhitecheck() -> void:
if type == 0 and Input.isactionpressed("kill"):
emit_signal("kill")
score += score

what is the issue... ?

Thanks a lot !!

Godot version 3.3
in Engine by (46 points)

Hold the space bar down and then enter the zone and see if that kills the enemy.

Yes it does ! I dont understand why...

When is on_enemy_white_check called?

I have an Area2D on my enemy. When the player enters it:

func _on_Area2D_body_entered(body: Node) -> void:
     emit_signal("white_check")

So that function only runs once when the player enters the area? You need to have the function run every time the player presses the kill button instead.

So instead of checking if the player is pressing the kill button when they enter the white area, you should check if the player is in the white area when they press the kill button. Use the _unhandled_input() function for this.

Oh god, that's brillant. I'll try this, thanks ! I'll watch a tutorial on this function, i've never use it before.

I definitivly don't understant why to use this method haha...

1 Answer

0 votes

Have you defined the action in the project settings?
You also need to use Input.isactionjust_pressed("kill") because this happens just once for each enemy.

by (1,051 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.