2023-11-15 15:19:40 +11:00
|
|
|
extends ExplosiveProjectile
|
|
|
|
class_name HomingProjectile
|
|
|
|
|
|
|
|
var target : Node3D
|
2023-11-17 20:49:38 +11:00
|
|
|
var acceleration := 50.0
|
|
|
|
var max_speed := 13.0
|
2023-11-15 15:19:40 +11:00
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
if is_instance_valid(target):
|
2023-11-17 20:49:38 +11:00
|
|
|
direction = global_position.direction_to(target.sprite.global_position)
|
2023-11-15 15:19:40 +11:00
|
|
|
#apply_central_force(direction * acceleration)
|
|
|
|
|
|
|
|
|
|
|
|
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
2023-11-17 20:49:38 +11:00
|
|
|
state.linear_velocity = state.linear_velocity.limit_length(state.linear_velocity.length() * (1.0 - 0.08))
|
2023-11-15 15:19:40 +11:00
|
|
|
state.linear_velocity += direction * acceleration * state.step
|
|
|
|
state.linear_velocity = state.linear_velocity.limit_length(max_speed)
|