23 lines
625 B
GDScript
23 lines
625 B
GDScript
extends RigidBody2D
|
|
|
|
@onready var hurtbox: Area2D = $HurtArea2D
|
|
|
|
@export var launch_speed: float = 400
|
|
@export var speed_mult: float = 1.08
|
|
|
|
var is_hit: bool = false
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
hurtbox.connect("area_entered", _on_hit)
|
|
launch_random()
|
|
|
|
|
|
func launch_random():
|
|
var angle = randf_range(-PI/3, PI/3) + PI * float(randi()%2)
|
|
linear_velocity = Vector2(cos(angle), sin(angle)) * launch_speed
|
|
|
|
|
|
func _on_hit(area: Area2D) -> void:
|
|
if area.is_in_group("paddle"):
|
|
linear_velocity = linear_velocity.normalized() * linear_velocity.length() * speed_mult
|