Skip to content

Commit

Permalink
style: trying to enemy's eye follow player
Browse files Browse the repository at this point in the history
  • Loading branch information
megarubber committed Mar 6, 2022
1 parent 1f13c9b commit ac07d05
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions enemy/sprites_enemy2/EyesEnemy.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
extends Sprite

# Nodes Referencing
onready var child = get_children()[0]
onready var eyes = get_children()[0]
onready var player = get_tree().get_current_scene().get_node("Player")

# Constants
const MAX_EYE_UP = -3

# Variables
var max_dist = 15
var max_dist = 10

func _process(_delta) -> void:
# Eyes following mouse
var mouse_pos = get_parent().position
var dir = Vector2.ZERO.direction_to(mouse_pos)
var dist = mouse_pos.length()
var dist = global_position.distance_to(player.global_position)
var dir = Vector2.direction_to(player.position)
#if mouse_pos.y < MAX_EYE_UP:
# dir.y = 0
child.position = dir * min(dist, max_dist)
eyes.position = dir * min(dist, max_dist)
4 changes: 2 additions & 2 deletions enemy/sprites_enemy2/FollowerEnemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ script = ExtResource( 9 )
position = Vector2( -2, 100 )
scale = Vector2( 0.104576, 0.104576 )
frames = SubResource( 6 )
frame = 4
frame = 1
playing = true

[node name="Head" type="Sprite" parent="."]
Expand Down Expand Up @@ -118,7 +118,7 @@ collision_mask = 2
collision_layer = 8

[node name="AreaShape" type="CollisionShape2D" parent="Area2D"]
position = Vector2( -8, -260 )
position = Vector2( -8, -263 )
shape = SubResource( 7 )

[node name="GunSprite" type="Sprite" parent="."]
Expand Down
2 changes: 1 addition & 1 deletion levels/TestLevel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,4 @@ tile_data = PoolIntArray( 65528, 0, 0, 65529, 2, 0, 65530, 2, 0, 65531, 2, 0, 65
position = Vector2( 992, -79 )

[node name="FollowerEnemy" parent="." instance=ExtResource( 4 )]
position = Vector2( -451, -238 )
position = Vector2( -444, -236 )

0 comments on commit ac07d05

Please sign in to comment.