gai-godot-games/pathfinding-algorithms/scenes/custom-solver/CustomNavMovement.gd

23 lines
645 B
GDScript
Raw Normal View History

2024-11-12 15:00:58 +01:00
extends CharacterBody2D
const MAX_SPEED: float = 300.0
const ACCELERATION: int = 2400
@onready var graph: NavigationGraph = $"../NavGraph"
func _physics_process(delta: float) -> void:
var movement: Vector2 = Vector2()
var next_pos: Vector2 = graph.determine_next_position(position, get_global_mouse_position())
movement = next_pos - global_position
if movement.length() < 20:
movement = -velocity * 0.2
else:
movement = movement.normalized() * ACCELERATION * delta
velocity += movement
if velocity.length() > MAX_SPEED:
velocity = velocity.normalized() * MAX_SPEED
move_and_slide()