Hello! I'm trying to make a simple air hockey game(while grasping the basics) in Godot 3.5.1, but stuck with this signal issue.
My current goal is to send current speed of player_paddle to a puck("ball" in my project) in order to change speed of puck object.
ball.gd
extends KinematicBody2D
var ball_speed = 100
var direction = Vector2(1,1)
var pdl1_speed = 100
func _physics_process(delta):
var velocity = pdl1_speed * direction * delta
var collision = move_and_collide(velocity)
if collision != null:
direction = direction.bounce(collision.normal)
func _on_player_paddle_sent_speed(paddle_speed) -> void:
pdl1_speed = paddle_speed
print("Signal connected")
player_paddle.gd
extends KinematicBody2D
signal sent_speed(paddle_speed)
var move_direction = Vector2(0,0)
var velocity = 0
var speed = 2000
func _physics_process(delta):
move_direction.x = int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))
move_direction.y = (int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up"))) / float(2)
var motion = move_direction.normalized() * speed
velocity = motion
move_and_slide(velocity)
func _on_Area2D_body_entered(body):
if body.name == "ball":
emit_signal("sent_speed", speed)
print("hit detected")
But no matter what, on collision ball speed is still the same.