AI now shoots, needs more randomization

This commit is contained in:
Paul Black 2022-03-07 20:13:43 -07:00
parent 39b8564261
commit 80a2465779

View file

@ -1,10 +1,21 @@
extends KinematicBody
export (PackedScene) var Bullet = preload("res://Objects/Bullet/Bullet.tscn")
var _bullettimer = null
var speed = 10
var gravity = 100
var velocity = Vector3.ZERO
onready var player = get_node("/root/Spatial/PlayerTank")
func _ready(): ##For bullet timer
_bullettimer = Timer.new()
add_child(_bullettimer)
_bullettimer.connect("timeout", self, "_bullet_fire")
_bullettimer.set_wait_time(1.0)
_bullettimer.set_one_shot(false) # Make sure it loops
_bullettimer.start()
func _physics_process(delta):
velocity = Vector3.ZERO
@ -13,3 +24,10 @@ func _physics_process(delta):
velocity = (player.transform.origin - transform.origin).normalized() * speed # make velocity direction equal to player direction
velocity = move_and_slide(velocity) # Move AI towards player
func _bullet_fire():
if player != null:
var b = Bullet.instance()
owner.add_child(b)
b.transform = $CollisionShape/Tank/BulletGenerator.global_transform
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity