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
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
I’ll check this out and see if it works, Thanks
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:
- Use
move_and_collide
only when you want the object to move - 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 .
Any and ALL suggestions would help me out a ton, Thanks
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!
@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
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
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
After 15 days of back and forth communication with @gertkeno, I’ve finally gotten the solution to my problem . Here’s the newly updated code I had for this (Once again Special thanks to @gertkeno:
extends CharacterBody2D
@export var speed = 500
var score = 0
var can_add_score = true
var speed_increase = 10
var colliding_with_paddle: bool = false
var collisions_with_paddle: int = 0
@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
colliding_with_paddle = 0
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/-4)
elif direction == 4:
velocity = Vector2.RIGHT.rotated(PI/-4)
func _physics_process(delta: float) -> void:
var collision = move_and_collide(velocity * speed * delta)
if not collision:
return
if collision.get_collider().name == "Paddle" and %Timer.is_stopped():
score += 1
label.text = str(score)
%Timer.start()
speed += speed_increase
hit_sound_2.play()
hit_sound.play()
if collision.get_collider().name == "Borders":
hit_sound.play()
if collision.get_collider().name == "DeathArea":
game_over_sound.play()
visible = false
game_over_screen.visible = true
get_tree().paused = true
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())
var wall_normal = collision.get_normal()
var hit_left: bool = wall_normal.x > 0.1
var hit_top: bool = wall_normal.y > 0.1
var hit_bot: bool = wall_normal.y < -0.1
var hit_right: bool = wall_normal.x < -0.1
if hit_bot and (hit_left or hit_right): #bottom and left or right (could be a corner)
velocity *= -1 #invert velocity
if hit_left:
var moving_left: bool = velocity.y < 0
velocity = (Vector2.RIGHT).rotated(PI/4 * (-1 if moving_left else 1))
elif hit_top:
var moving_up: bool = velocity.x > 0
velocity = (Vector2.DOWN).rotated(PI/4 * (-1 if moving_up else 1))
elif hit_bot:
var moving_bot: bool = velocity.x < 0
velocity = (Vector2.UP).rotated(PI/4 * (-1 if moving_bot else 1))
elif hit_right:
var moving_right: bool = velocity.y > 0
velocity = (Vector2.LEFT).rotated(PI/4 * (-1 if moving_right else 1))
if collider_name == "Paddle":
collisions_with_paddle += 1
colliding_with_paddle = true
if %PaddleTimer.is_stopped() == true:
%PaddleTimer.start()
velocity.y = -absf(velocity.y) # always bounce upwards on paddle
collision.get_collider().short_disable() # paddle disable function
elif collider_name != "Paddle":
colliding_with_paddle = false
elif collider_name != "Paddle":
colliding_with_paddle = false
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()
func short_disable() -> void:
if colliding_with_paddle == true:
var old_layer = self.collision_layer
var old_mask = self.collision_mask
self.set_collision_mask_value(3, true)
self.set_collision_mask_value(1, false)
await get_tree().create_timer(0.1).timeout
self.set_collision_mask_value(3, true)
self.set_collision_mask_value(1, true)
self.collision_mask = old_mask
func _on_paddle_timer_timeout():
if colliding_with_paddle == true:
short_disable()
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.