Bat
parent
3a4b647df5
commit
48c56c3d1a
|
@ -13,6 +13,8 @@ script = ExtResource( 2 )
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
centered = false
|
centered = false
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
position = Vector2( 7, 4 )
|
position = Vector2( 7, 4 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
var speed = 48
|
var speed = 64
|
||||||
|
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
get_node("Sprite").flip_h = true if $"../Player".global_position.x > self.position.x else false
|
get_node("Sprite").flip_h = true if $"../Player".global_position.x > self.position.x else false
|
||||||
|
|
||||||
func _physics_process(_delta):
|
func _physics_process(_delta):
|
||||||
if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) > 48:
|
if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) > 64:
|
||||||
velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8)))
|
velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8)))
|
||||||
velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8)))
|
velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8)))
|
||||||
else:
|
else:
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
|
|
||||||
if abs($"../Player".velocity.x) > 0 and position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 48:
|
if abs($"../Player".velocity.x) > 0 and position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 64:
|
||||||
velocity.x = speed * 2 * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
||||||
velocity.y = speed * 2 * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
||||||
|
|
||||||
if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 32:
|
if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) < 48:
|
||||||
velocity.x = speed * 2 * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
||||||
velocity.y = speed * 2 * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 8, $"../Player".global_position.y + 8)) + 180)
|
||||||
|
|
||||||
|
|
||||||
move_and_slide(velocity)
|
move_and_slide(velocity)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue