0 votes

Anyone have any insight on how to code this type of enemy? I've been toying with it for a couple of days working with code originally used to make ballistic projectiles like arrows arc to the player's position but it's just not quite coming together.
It doesn't seem like it should be too difficult because I can determine the distance from the enemy's position to the player's position but I wonder if there's an equation or something that I'm unaware of to make it work? It's a pretty common pattern for enemies in 2D games too, so it's odd that there isn't much information out there about implementing them.

Godot version 3.5
in Engine by (20 points)

1 Answer

+1 vote

Hey there!

I guess you could use the player position in order to find the direction of the jump, something like this maybe will give you some direction.

extends KinematicBody2D
var player

func _ready():
    player = get_node('/root/Node2D/Player')

func jump_to_player():
    var jump_direction = (position - player.position)
    jump_direction.y -= 30 # Adding -30 to Y direction (UP)
    jump_direction.y = clamp(jump_direction.y, -60, 0) # Max JumpForce is -60
    move_and_slide(jump_direction, Vector2.UP)
by (20 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.