0 votes

I need a enemy for my character, could anybody help me create my enemy. I am new to Godot, I just picked up the engine a few days ago. When my enemy is touched, I would like my player to disappear, and when my enemy's head is jumped on, I would like my enemy to disappear. Here is the code I used for my player:

extends KinematicBody2D

var score : int = 0

var speed : int = 200
var jumpforce : int = 490
var gravity : int = 800

var vel : Vector2 = Vector2()

onready var sprite : Sprite = get_node("Sprite")

func physicsprocess(delta):

vel.x = 0

if Input.is_action_pressed("move_left"):
    vel.x -= speed
if Input.is_action_pressed("move_right"):
    vel.x += speed

vel = move_and_slide(vel, Vector2.UP)

vel.y += gravity * delta

if Input.is_action_just_pressed("jump") and is_on_floor():
    vel.y -= jumpforce

if vel.x < 0:
    sprite.flip_h = false
elif vel.x > 0:
    sprite.flip_h = false

I hope this helps! Thank you Godot Community!
Edit: I do not know how to make the code go into the box thing

in Engine by (12 points)

2 Answers

0 votes

I think the concept of Signals will help you out a lot here: https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html.

Essentially, just make an Area2D node on your enemy, and connect the bodyentered signal to a function. In that function, if the player is above the enemy, just queuefree() the enemy. If not, queue_free() the player.

by (14 points)
0 votes


I think GDQuest has video to create such as thing stomp the enemy to kill it

Link to Video

Best regards

by (126 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 Frequently asked questions and 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 [email protected] with your username.