properly handle angle in ball launch
This commit is contained in:
parent
ab075045d5
commit
6c22f929b2
1 changed files with 6 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ extends RigidBody2D
|
|||
|
||||
@onready var hurtbox: Area2D = $HurtArea2D
|
||||
|
||||
@export var launch_speed: float = 400
|
||||
@export var launch_speed: float = 200
|
||||
@export var speed_mult: float = 1.08
|
||||
|
||||
var is_hit: bool = false
|
||||
|
|
@ -14,9 +14,9 @@ func _ready() -> void:
|
|||
launch()
|
||||
|
||||
|
||||
func launch(angle: float = 0) -> void:
|
||||
func launch(angle: float = 0, min_speed: float = 150, max_speed: float = 250) -> void:
|
||||
angle = randf_range(-PI/3, PI/3) + PI * float(randi()%2) if angle == 0 else angle
|
||||
linear_velocity = Vector2(cos(angle), sin(angle)) * launch_speed
|
||||
linear_velocity = Vector2(cos(angle), sin(angle)) * randf_range(min_speed, max_speed)
|
||||
|
||||
|
||||
func _on_hit(hitbox: Area2D) -> void:
|
||||
|
|
@ -26,7 +26,9 @@ func _on_hit(hitbox: Area2D) -> void:
|
|||
print("ball not hit yet")
|
||||
var player: Player = hitbox.get_parent()
|
||||
var timer: Timer = player.hit_timer
|
||||
launch()
|
||||
var angle: float = randf_range(3*PI/4, PI/4) * (-1 if player.id == 1 else 1)
|
||||
launch(angle)
|
||||
print("ball hit")
|
||||
if not timer.is_connected("timeout", _on_hit_end):
|
||||
timer.connect("timeout", _on_hit_end)
|
||||
EventBus.ball_hit.emit(player.id, linear_velocity)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue