35 lines
875 B
GDScript
35 lines
875 B
GDScript
extends Node2D
|
|
|
|
|
|
@export var speed: float = 0.0
|
|
@export_custom(0, "radians_as_degrees") var rotation_speed: float
|
|
@export var launch_speed: float
|
|
|
|
@export_group("Internal References")
|
|
@export var rotation_pivot: Node2D
|
|
@export var collision_shape: CollisionShape2D
|
|
|
|
|
|
var _player: Player = null
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if is_zero_approx(speed):
|
|
collision_shape.disabled = false
|
|
rotation_pivot.rotation = 0.0
|
|
else:
|
|
collision_shape.disabled = true
|
|
rotation_pivot.rotation += rotation_speed * delta
|
|
if _player:
|
|
var dir = -to_local(_player.global_position).orthogonal()
|
|
_player.launch(_player.velocity + dir * launch_speed * speed * delta)
|
|
|
|
|
|
func _on_player_detector_body_entered(body: Node2D) -> void:
|
|
if body is Player:
|
|
_player = body
|
|
|
|
|
|
func _on_player_detector_body_exited(body: Node2D) -> void:
|
|
if body is Player:
|
|
_player = null
|