• Godot Help
  • Can't send signal to other object on collision

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.

I normally connect signals using code, but connecting a signal with the editor GUI like that should work too.

Is this getting executed?
print("Signal connected")

If so, you should also print the parameter paddle_speed to verify it's correct.

    So this isn't executed either?
    print("hit detected")

    The code you posted isn't indented properly. Does the code really look like that?

      DaveTheCoder
      Yes, even that is not executing.

      Regarding code, honestly I don't quite get this part of GDscript, gonna look into that.

      That indentation looks correct. The problem is not with the signal, but with the collision not being detected.

      Can you upload your project, if it's not too big? Either I or someone else could take a look at it.