enemy now can walk on slopes

This commit is contained in:
Rendo 2025-07-27 21:11:10 +05:00
commit eec69524ee
4 changed files with 35 additions and 20 deletions

View file

@ -9,7 +9,7 @@ func _process(delta: float) -> void:
if Engine.is_editor_hint():
camera = EditorInterface.get_editor_viewport_3d().get_camera_3d()
# Angle between camera's -basis.z (forward direction) and direction to camera
var angle = vec3_to_vec2(-global_transform.basis.z).angle_to(vec3_to_vec2(global_position - camera.global_position)) + PI
var angle = vec3_to_vec2(global_transform.basis.z).angle_to(vec3_to_vec2(global_position - camera.global_position)) + PI
var chosen_index = 0
for i in rotations.keys():
if abs(angle-i) < abs(angle-chosen_index):

View file

@ -13,8 +13,6 @@ func _physics_process(delta: float) -> void:
if navigation_agent.is_navigation_finished(): return
if navigation_agent.is_target_reachable():
var direction_to_next = (navigation_agent.get_next_path_position() - move_target.global_position).normalized()
var delta_angle = clamp(move_target.basis.z.signed_angle_to(direction_to_next,Vector3.UP),-rotation_speed,rotation_speed)
move_target.rotation.y += delta_angle
move_target.global_position += move_target.basis.z * max_speed * delta
var pos = navigation_agent.get_next_path_position()
move_target.look_at(pos)
move_target.global_position += move_target.global_position.direction_to(pos) * max_speed * delta