make zombie AI more useful
This commit is contained in:
parent
1dc6d985bb
commit
e70b8e7968
5
Main.gd
5
Main.gd
|
@ -6,12 +6,13 @@ var relic_left = 5
|
|||
|
||||
func add_zombie():
|
||||
var zombie = zombie_scene.instance()
|
||||
zombie.set_player($Player)
|
||||
var zombie_spawn_location = get_node("Enemies/zombiePath/zombieSpawnLocation")
|
||||
zombie_spawn_location.offset = randi()
|
||||
zombie.position = zombie_spawn_location.position
|
||||
if zombie.position.distance_to($Player.position) > 40:
|
||||
zombie.look_at($Player.position)
|
||||
zombie.linear_velocity = Vector2(100, 0).rotated(zombie.rotation)
|
||||
# zombie.look_at($Player.position)
|
||||
# zombie.linear_velocity = Vector2(100, 0).rotated(zombie.rotation)
|
||||
zombie.connect("hit", self, 'player_got_hit')
|
||||
add_child(zombie)
|
||||
else:
|
||||
|
|
23
Zombie.gd
23
Zombie.gd
|
@ -1,7 +1,28 @@
|
|||
extends RigidBody2D
|
||||
extends KinematicBody2D
|
||||
|
||||
signal hit
|
||||
|
||||
onready var player
|
||||
|
||||
func set_player(p):
|
||||
player = p
|
||||
|
||||
var velocity = Vector2()
|
||||
var speed = 2000
|
||||
|
||||
func _process(delta):
|
||||
if player.position.x > position.x:
|
||||
velocity.x += speed
|
||||
if player.position.x < position.x:
|
||||
velocity.x -= speed
|
||||
if player.position.y > position.y:
|
||||
velocity.y += speed
|
||||
if player.position.y < position.y:
|
||||
velocity.y -= speed
|
||||
|
||||
func _physics_process(delta):
|
||||
velocity = move_and_slide(velocity * delta)
|
||||
|
||||
func _on_Area2D_body_entered(body):
|
||||
if body.is_in_group("player"):
|
||||
print("player hit")
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 13, 14.5 )
|
||||
|
||||
[node name="RigidBody2D" type="RigidBody2D"]
|
||||
gravity_scale = 0.0
|
||||
[node name="RigidBody2D" type="KinematicBody2D"]
|
||||
collision/safe_margin = 0.001
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_group_": true
|
||||
|
@ -22,7 +22,7 @@ scale = Vector2( 1.0262, 1.01107 )
|
|||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2( 0, 0.5 )
|
||||
scale = Vector2( 0.744407, 0.756047 )
|
||||
scale = Vector2( 0.764139, 0.776087 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D2" type="CollisionShape2D" parent="."]
|
||||
|
|
Loading…
Reference in New Issue