How do I fix collision errors at the edge of my paddle?

Yeah that’s crazy, any chance you could send the whole project in a zip? From the last video it really seems like that was the problematic line, even the dust particles started spawning distances away.

I’m not comfortable with sending my entire project though, Is it possible for you to try out the code yourself and see how it would be fixed?

sending the project would be the only way for me to really try it out. I’ll see if I can make any sort of minimal project with the script you posted

In a jank test project it worked for me, here is the end ball script. and the paddle script. Since I couldn’t replicate the issue I believe the paddle script might be the culprit

# Ball.gd
extends CharacterBody2D

@export var speed = 600
var score = 0
var can_add_score = true
var speed_increase = 10
@onready var label = $"../Score"
@onready var game_over_screen = $"../GameOverScreen"
@onready var hit_sound = $Hit_Sound
@onready var hit_sound_2 = $Hit_Sound2
@onready var pop_sound = $Pop_Sound
@onready var game_over_sound = $Game_Over_Sound

func _ready():
	visible = true
	var direction = 1
	direction = randi_range(1, 4)
	if direction == 1:
		velocity = Vector2.RIGHT.rotated(PI/4)
	elif direction == 2:
		velocity = Vector2.LEFT.rotated(PI/4)
	elif direction == 3:
		velocity = Vector2.LEFT.rotated(PI/-5)
	elif direction == 4:
		velocity = Vector2.RIGHT.rotated(PI/-5)

func _physics_process(delta: float) -> void:
	var collision = move_and_collide(velocity * speed * delta)
	if not collision:
		return

	# removed velocity.bounce * speed

	if collision.get_collider().name == "Paddle" and %Timer.is_stopped():
		score += 1
		label.text = str(score)
		%Timer.start()
		speed += 10
		print(speed)
		hit_sound_2.play()
		hit_sound.play()
	if collision.get_collider().name == "Borders":
		hit_sound.play()
	if collision.get_collider().name == "DeathArea":
		pop_sound.play()
		game_over_sound.play()
		visible = false
		game_over_screen.visible = true
		get_tree().paused = true

	# Fixing logic here, cosmetic only
	var collider_name: String = collision.get_collider().name
	if (collider_name == "Paddle" or collider_name == "Borders") and %Dust.emitting == true:
		Spawn_Dust_2(collision.get_position())
	else:
		Spawn_Dust(collision.get_position())

	velocity = velocity.bounce(collision.get_normal())

func _on_timer_timeout():
	%Timer.stop()

func _on_play_again_pressed():
	print("Restarted")
	game_over_screen.visible = false
	get_tree().paused = false
	get_tree().change_scene_to_file("res://Scenes/Game.tscn")

func _on_menu_pressed():
	print("Menu button clicked!")
	game_over_screen.visible = false
	get_tree().paused = false
	get_tree().change_scene_to_file("res://Scenes/Start_Menu.tscn")

func Spawn_Dust(collision_point: Vector2) -> void:
	%Dust.global_position = collision_point
	%Dust.emitting = true
	%Dust.restart()

func Spawn_Dust_2(collision_point: Vector2) -> void:
	%Dust2.global_position = collision_point
	%Dust2.emitting = true
	%Dust2.restart()
# Paddle.gd
extends CharacterBody2D

func _ready() -> void:
	velocity = Vector2.ZERO

func _physics_process(delta: float) -> void:
	var input := Input.get_axis("Left", "Right")
	velocity.x = input * 400
	var collision := move_and_collide(velocity * delta, true)
	if collision == null:
		position += velocity * delta
1 Like

I’m going to bed now though, so I’ll have to wait until tomorrow to fix this issue and find a solution. See you later :wave:

1 Like

I’ll check this out and see if it works, Thanks :smiley:
I also thought of maybe changing the velocity.bounce to -velocity.bounce, Might work or cause the ball to go hyper again.

Also, could you show me where I could learn more about this whole collision script thing so I can better understand code like this and be able to fix these issues on my own?

I changed my paddle script to this, but no difference.

I only read the docs, I suppose college algebra helped too.

I didn’t change much, the only issues I’ve pointed out were:

  1. Use move_and_collide only when you want the object to move
  2. only bounce once per colllision

I decided to try and add the velocity.bounce to the if statements instead of where the dust is activated, not much of a difference either, but I think it’s a good change, Maybe it is? idk.

I could try using the docs to get better knowledge of this, But is there a video or website maybe that could better teach me this step by step?

I’ve been searching for a long while now, and I STILL can’t find a way to fix this bug. Either I’m still doing something wrong, or this is just on the engine itself and the fact that the paddle moving in a horizontal position just doesn’t work :smiling_face_with_tear:.

Any and ALL suggestions would help me out a ton, Thanks :smiley:

Hey ZV1LLE,

I’ve been creeping this post since you posted the other day.

I think at this point you should probably share the zip with gert if you want to get that glitch fixed. I think if this was a larger project/dream game I would have the same reservations but since it’s a pong clone type/learning to code game for you, there’s nothing to lose except an opportunity for free tutelage.

Gert’s all over these forums and is super helpful. If you’d rather not share a link on the forum to your project, maybe DM him and send it directly? Or delete it after they confirm they’ve downloaded it.

Welcome to Godot!

1 Like

@BrutalDevon Thanks for the helpful comment! I’d also like to inform you that I’ve sent the project to him and he’s currently helping fix the issue, Thanks :smiley:

1 Like

I haven’t really been asking anyone (besides from @gertkeno) to help me out, so does anyone still have any suggestions to help me out with this bug?

I’ll post the script and any images if anyone needs them to help me out. Thanks in advance :smiley:

What problems I’m facing right now:


My main goal is for the ball to move at a fixed angle no matter where it hits