-
Notifications
You must be signed in to change notification settings - Fork 1
/
enemy_frog.gd
38 lines (29 loc) · 923 Bytes
/
enemy_frog.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extends CharacterBody2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var player
var chase = false
var SPEED = 50
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
velocity.y += gravity * delta #gravity for enemy:frog
if chase == true:
player = get_node("../../Player/Player")
var direction = (player.position - self.position)
if direction.x > 0:
print("R")
get_node("AnimatedSprite2D").flip_h = true
else:
print("L")
get_node("AnimatedSprite2D").flip_h = false
velocity.x = direction.x * SPEED
else:
velocity.x = 0
move_and_slide()
func _on_player_detection_body_entered(body):
if body.name == "Player":
chase = true
func _on_player_detection_body_exited(body):
chase = false