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