AI now follows player
This commit is contained in:
parent
6d5e7d23da
commit
39b8564261
1 changed files with 6 additions and 10 deletions
|
@ -1,19 +1,15 @@
|
||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
var speed = 15
|
var speed = 10
|
||||||
var gravity = 100
|
var gravity = 100
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
# onready var player = find_node("PlayerTank") ## FIXME
|
onready var player = get_node("/root/Spatial/PlayerTank")
|
||||||
onready var player = get_node("/root/Spatial/PlayerTank/CollisionShape")
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
var direction = Vector3.ZERO
|
velocity = Vector3.ZERO
|
||||||
|
|
||||||
if player != null: # Makes sure player is not an empty variable (not equal to nill/null)
|
if player != null: # Makes sure player is not an empty variable (not equal to nill/null)
|
||||||
$CollisionShape.look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0))
|
$CollisionShape.look_at(Vector3(player.global_transform.origin.x, global_transform.origin.y, player.global_transform.origin.z), Vector3(0,1,0)) # Look at player
|
||||||
direction.z -= 1 ### CODE FROM HERE DOWN NEEDS IMPROVEMENT (AI walks up nonstop and not towards player...)
|
velocity = (player.transform.origin - transform.origin).normalized() * speed # make velocity direction equal to player direction
|
||||||
velocity.x = direction.x * speed
|
velocity = move_and_slide(velocity) # Move AI towards player
|
||||||
velocity.z = direction.z * speed
|
|
||||||
velocity.y -= gravity * delta
|
|
||||||
velocity = move_and_slide(velocity, Vector3.UP)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue