Enemies dont chases from accross the map, only close
This commit is contained in:
parent
c90373b9b9
commit
fd22a155cf
15
ai/Enemy.gd
15
ai/Enemy.gd
|
@ -13,6 +13,7 @@ func apply_gravity(delta, modifier = 1):
|
|||
velocity.y += gravity * delta * modifier
|
||||
|
||||
func _physics_process(_delta):
|
||||
var dist = global_position.distance_to(Globals.player)
|
||||
if Globals.player != null:
|
||||
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
|
||||
velocity = Vector2(0, 0)
|
||||
|
@ -22,15 +23,19 @@ func _physics_process(_delta):
|
|||
velocity = Vector2(0, 0)
|
||||
elif $RayCast2D4.get_collider() != null && $RayCast2D4.get_collider().has_method("get_type") and $RayCast2D4.get_collider().get_type() == "player":
|
||||
velocity = Vector2(0, 0)
|
||||
else:
|
||||
if dist <= 400:
|
||||
velocity.x = position.direction_to(Globals.player).normalized().x
|
||||
else:
|
||||
velocity = Vector2(0, 0)
|
||||
apply_gravity(_delta)
|
||||
velocity.x *= speed
|
||||
velocity = move_and_slide(velocity, UP)
|
||||
if velocity.x > 0:
|
||||
# $(Enemy Sprite).flip_h = false
|
||||
elif velocity.x < 0:
|
||||
# $(Enemy Sprite).flip_h = true
|
||||
|
||||
#FOR FLIPPING THE SPRITE RIGHT AND LEFT DEPENDING ON WHICH WAY THEY FACING
|
||||
#if velocity.x > 0:
|
||||
# $(Enemy Sprite).flip_h = false
|
||||
#elif velocity.x < 0:
|
||||
# $(Enemy Sprite).flip_h = true
|
||||
|
||||
if is_on_wall() and is_on_floor():
|
||||
velocity.y = -150
|
||||
|
|
|
@ -6,7 +6,6 @@ var gravity =500
|
|||
var health = 5
|
||||
const UP = Vector2(0, -1)
|
||||
|
||||
|
||||
onready var ShootDelay : Timer = $ShootDelay
|
||||
onready var ProjectileSpawn: Node2D = $Position2D
|
||||
|
||||
|
@ -16,6 +15,7 @@ func apply_gravity(delta, modifier = 1):
|
|||
velocity.y += gravity * delta * modifier
|
||||
|
||||
func _physics_process(_delta):
|
||||
var dist = global_position.distance_to(Globals.player)
|
||||
if Globals.player != null:
|
||||
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
|
||||
velocity = Vector2(0, 0)
|
||||
|
@ -53,8 +53,10 @@ func _physics_process(_delta):
|
|||
temp.launch_upright()
|
||||
ShootDelay.start()
|
||||
queue_free()
|
||||
else:
|
||||
if dist <= 400:
|
||||
velocity.x = position.direction_to(Globals.player).normalized().x
|
||||
else:
|
||||
velocity = Vector2(0, 0)
|
||||
apply_gravity(_delta)
|
||||
velocity.x *= speed
|
||||
velocity = move_and_slide(velocity, UP)
|
||||
|
|
|
@ -61,7 +61,7 @@ position = Vector2( -7.56425, -7.87261 )
|
|||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
hframes = 8
|
||||
frame = 4
|
||||
frame = 5
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "Devil"
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,7 @@ func apply_gravity(delta, modifier = 1):
|
|||
velocity.y += gravity * delta * modifier
|
||||
|
||||
func _physics_process(_delta):
|
||||
var dist = global_position.distance_to(Globals.player)
|
||||
if Globals.player != null:
|
||||
if $RayCast2D.get_collider() != null && $RayCast2D.get_collider().has_method("get_type") and $RayCast2D.get_collider().get_type() == "player":
|
||||
velocity = Vector2(0, 0)
|
||||
|
@ -49,8 +50,10 @@ func _physics_process(_delta):
|
|||
temp.global_position = ProjectileSpawn.global_position
|
||||
temp.launch_upright()
|
||||
ShootDelay.start()
|
||||
else:
|
||||
if dist <= 400:
|
||||
velocity.x = position.direction_to(Globals.player).normalized().x
|
||||
else:
|
||||
velocity = Vector2(0, 0)
|
||||
apply_gravity(_delta)
|
||||
velocity.x *= speed
|
||||
velocity = move_and_slide(velocity, UP)
|
||||
|
|
Loading…
Reference in a new issue