so i have been making a enemy that chases you around but it doesent seem to work when i enter its Collison shape my game would just close on its on
enemy code:
extends CharacterBody2D
var speed = 25
var player_chase = false
var player = null
func _physics_process(delta):
if player_chase:
position += (player.poistion - position)/speed
func _on_detection_area_body_entered(body):
player = body
player_chase = true
func _on_detection_area_body_exited(body):
player = null
player_chase = false
yes it is making just make sure
i did fix it but my enemy wont chase and the game still closes
read what the error said?
line code 14
func player_movement(delta):
that shouldnt force close the game though, so now it’s just not chasing the player right?
have you tried to just
position += Vector2(10,10)
will it move?
it works but the enemy seems to go in the other direction and not towards me
yes, it should work like that because it moves 10 pixel down and 10 pixel right every physics frame when it detected player
are your player and enemy in the same child of a node? aka siblings node?
yes there are siblings node
i am so sorry but i have to go and will be back in around 20-30m can u help me when i come back
then it’s probably you divided by 25 speed is too small to even notice the movement
try with 0.01 see if it moves
change to this:
global_position += (player.global_position - global_position)/speed

instead of chasing the player sprite, i just make the sprite2d to “chase” my mouse
when i try that it feels like that i am chasing the enemy and the enemy is just making some distance
then something should be changed on the code, so the enemy wont run away when you go near it
then what should i change to fix it
i dont know how it looks there, if my mouse global position is the player’s global position, and when i try to go near the accelerating/chasing sprite2d, it didnt move away
show your code once again
enemy code:
extends CharacterBody2D
var speed = 25
var player_chase = false
var player = null
func _physics_process(delta):
if player_chase:
position += (player.poistion - position)/speed
func _on_detection_area_body_entered(body):
player = body
player_chase = true
func _on_detection_area_body_exited(body):
player = null
player_chase = false