26 lines
778 B
GDScript
26 lines
778 B
GDScript
extends CharacterBody3D
|
|
|
|
|
|
@export var acceleration: float
|
|
@export var speed: float
|
|
@export var vertical_speed: float
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var target: Node3D = null
|
|
for node in get_tree().get_nodes_in_group(&"chaser_target"):
|
|
if node is Node3D:
|
|
if not target or (
|
|
global_position.distance_squared_to(node.global_position) <
|
|
global_position.distance_squared_to(target.global_position)
|
|
):
|
|
target = node
|
|
|
|
if target:
|
|
velocity += global_position.direction_to(target.global_position) * acceleration * delta
|
|
velocity = velocity.limit_length(speed)
|
|
velocity.y = (target.global_position.y - global_position.y) * vertical_speed
|
|
|
|
var col = move_and_collide(velocity * delta)
|
|
if col:
|
|
velocity = velocity.bounce(col.get_normal())
|