im making a wolfenstein clone in godot, and when the enemy dies, it keeps moving in the same direction and starts floating up into the sky
video (sorry the video looks like shit, obs was being laggy as fuck):
code:
extends CharacterBody3D
@onready var nav = get_tree().get_nodes_in_group("NavMesh")
@onready var player = get_tree().get_nodes_in_group("Player")
@onready var nav_agent = $NavigationAgent3D
var path = [] #hold the path coordinates from the enemy to the player
var path_index = 0 #keep track of which coordinate to go to
var speed = 3
var Health = 20
var gravity = -30
func _ready():
pass
func take_damage(DMG_amout):
Health -= DMG_amout
if Health <= 0:
Death()
func _physics_process(delta):
#if path_index < path.size():
#var direction = (path[path_index] - global_transform.origin)
#if direction.length < 1:
#path_index += 1
#else:
#move_and_slide()
#else:
#find_path(player.global_transform.origin)
velocity.y += gravity * delta
var current_location = global_transform.origin
var next_location = nav_agent.get_next_path_position()
var new_velocity = (next_location - current_location).normalized() * speed
nav_agent.set_velocity(new_velocity)
func update_target_location(Target):
nav_agent.target_position = Target
#func find_path(Target):
#path.get_simple_path(global_transform.origin,Target) #ask godot discord for help. got error "Invalid call. Nonexistent function 'get_simple_path' in base 'Array'"
#path_index = 0
func Attack(Target):
pass
func Death():
set_process(false)
set_physics_process(false)
$CollisionShape3D.disabled = true
if Health < -20:
$AnimatedSprite3D.play("Gib")
else:
$AnimatedSprite3D.play("Die")
func _on_navigation_agent_3d_velocity_computed(safe_velocity):
velocity = velocity.move_toward(safe_velocity, .25)
move_and_slide()