0 votes

I'm currently building a block breaking game without a tutorial. This is the first time I've seriously sat down to building something on my own with Godot.

Things are working as expected until the ball hits the Area2D "deadzone" which sends two signals, one to the paddle and one to the ball.

The issue is, when the ball hits the Area2D, it immediately breaks the left, lowest block. And then it resets. When I relaunch the ball, always relaunched from the position of the broken block.

This is the code that sends the signals on the HUD:

func _on_DeadZone_body_shape_entered(body_id, body, body_shape, area_shape):
  if body.name == "Ball":
    emit_signal("resetPaddle")
    emit_signal("resetBall")
    removelife()
    print("reset")

And here are the bits of code that handle the reset of the ball itself:

func _on_HUD_resetBall():
  should_reset = true

and

func _integrate_forces(state):
  if should_reset == true:
    should_reset = false
    state.linear_velocity = Vector2()
    var t = state.get_transform()
    t.origin.x = startingPos.x
    t.origin.y = startingPos.y
    state.set_transform(t)
    launched = false
    mode = MODE_STATIC
    sleeping = true

And these bits of code handle the ball follow and release:

func _physics_process(delta):
  if launched == false:
    var followPos = Vector2(paddle.position.x, startingPos.y)
    set_position(followPos)
    if Input.is_action_pressed("launch"):
        ballRelease()
    else:
        pass

func ballRelease():
  mode = MODE_RIGID
  var t = Timer.new()
  t.set_wait_time(0.01)
  t.set_one_shot(false)
  self.add_child(t)
  t.start()
  yield(t, "timeout")
  t.queue_free()

apply_impulse(Vector2(), Vector2(0,-1).normalized() * ball_speed)
launched = true

I have Staticbody2Ds set up for bumpers on the sides and top (but not the bottom) that only detect the paddle and the ball. Likewise the breakable blocks at the top only detect the ball. The ball itself only detects the paddle.

in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.