AI now shoots, needs more randomization
This commit is contained in:
parent
39b8564261
commit
80a2465779
1 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue