Move some movement logic from PathNavigator to NPC

This commit is contained in:
karl 2020-01-26 17:57:39 +01:00
parent 5f4bb0ffa4
commit 872280d31f
2 changed files with 9 additions and 2 deletions

View File

@ -3,6 +3,7 @@ class_name NPC
export(float) var turn_speed = 2.5
export(float) var speed = 8
var current_target
var current_look_target
@ -21,6 +22,13 @@ func _process(delta):
if diff.length() > 0.1:
look_at(transform.origin + target, Vector3.UP)
if current_target:
# Move towards the current goal
var direction_normalized: Vector3 = (current_target - transform.origin).normalized()
look_towards(direction_normalized)
move_towards(direction_normalized * speed)
func set_position(position: Vector3):
transform.origin = position

View File

@ -7,7 +7,6 @@ var _current_path_index
var _arrived_distance_threshold = 0.1
export(float) var speed = 8
export(NodePath) var body_nodepath
var navigation: Navigation
@ -48,7 +47,7 @@ func _process(delta):
var direction_normalized: Vector3 = (current_goal - _get_body_position()).normalized()
body.look_towards(direction_normalized)
body.move_towards(direction_normalized * speed)
body.move_towards(direction_normalized * body.speed)
# Returns the point we should currently be moving towards