Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | iAbrees |
Here is my enemy code.
Enemy Stops but doesn’t move again:
extends KinematicBody
export var SPEED = 3
var target = null
var nav: Navigation = null
var vel = Vector3()
func _physics_process(delta):
if target == null:
return
look_at(target.global_transform.origin, Vector3.UP)
var path = get_to_path(target.global_transform.origin)
if path.size() > 0:
move_along_path(path)
func get_to_path(target):
return nav.get_simple_path(global_transform.origin, target)
func move_along_path(path):
if path.size() <= 0:
return
path.remove(0)
var target = path[0]
if global_transform.origin.distance_to(target) < 0.1:
path.remove(0)
vel = (target - translation).normalized() * SPEED
vel = move_and_slide(vel)
func set_target(target):
self.target = target
func set_nav(nav):
self.nav = nav
func stop():
SPEED = 0
func move():
SPEED = 3
func _on_Area_area_entered(area):
if area.is_in_group("STOPPER"):
stop()
else:
vel = (target - translation).normalized() * 3extends KinematicBody
export var SPEED = 3
var target = null
var nav: Navigation = null
var vel = Vector3()
func _physics_process(delta):
if target == null:
return
look_at(target.global_transform.origin, Vector3.UP)
var path = get_to_path(target.global_transform.origin)
if path.size() > 0:
move_along_path(path)
func get_to_path(target):
return nav.get_simple_path(global_transform.origin, target)
func move_along_path(path):
if path.size() <= 0:
return
path.remove(0)
var target = path[0]
if global_transform.origin.distance_to(target) < 0.1:
path.remove(0)
vel = (target - translation).normalized() * SPEED
vel = move_and_slide(vel)
func set_target(target):
self.target = target
func set_nav(nav):
self.nav = nav
func stop():
SPEED = 0
func move():
SPEED = 3
func _on_Area_area_entered(area):
if area.is_in_group("STOPPER"):
stop()
else:
vel = (target - translation).normalized() * 3