i have been trying to make an enemy for my game that follows the player. heres an example .
after a bit of testing i discover that it wont jump at all.i tried changing my current attempt to making the enemy jump when i press the button which didn't work.then i tested it with print and then it worked so the detecting part works but the jump doesn't .hers the nodes i am currently using on the enemy
and heres the code:
extends KinematicBody2D
var velocity = Vector2()
var dead = false
var gravity = 1
var maxspeed = 225
var following_player = false
var jump = 700
onready var player = get_parent().get_node("player")
func dead():
dead = true
maxspeed = 0
$CollisionShape2D.set_deferred("disabled", true)
$Timer.start()
func _on_Area2D_body_entered(body):
if body == player:
following_player = true
func _on_Area2D_body_exited(body):
if body == player:
following_player = false
#these two are for spotting the player
func _physics_process(delta):
if following_player == true:
if player:
var direction = (player.position - position).normalized()
if not is_on_floor():
direction.y += gravity
move_and_slide(direction * maxspeed)
velocity.x = clamp(velocity.x,-maxspeed,maxspeed)
for i in get_slide_count():
var collision = get_slide_collision(i)
var object = collision.collider
func _on_Timer_timeout():
queue_free()
hopefully this is enough info to help me get past this hurdle