21 lines
515 B
GDScript
21 lines
515 B
GDScript
extends CharacterBody2D
|
|
|
|
const MAX_SPEED: float = 300.0
|
|
const ACCELERATION: int = 30
|
|
@export var nav: NavigationAgent2D
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var movement: Vector2 = Vector2()
|
|
|
|
nav.target_position = get_global_mouse_position()
|
|
|
|
movement = nav.get_next_path_position() - global_position
|
|
movement = movement.normalized() * ACCELERATION
|
|
|
|
velocity += movement
|
|
if velocity.length() > MAX_SPEED:
|
|
velocity = velocity.normalized() * MAX_SPEED
|
|
|
|
move_and_slide()
|