Godot Version
Godot 4.3
Question
I’m very new to Godot but after several hours of troubleshooting and researching I’m needing help with a very simple task.
I’m making a simple ping pong game. When the ball collides with a paddle, I want to reverse it’s velocity on the z plane.
I’ve imported models from blockbench as .gltf files (Node3D). I’ve set up the ball physics as simply as possible:
# Update velocity
velocity.y += gravity * delta
velocity.y = max(velocity.y, -max_fall_speed) # Cap fall speed
# Update position
position += velocity * delta
# Bounce logic
if position.y <= 0.08: # Assume table is at y = 0
position.y = 0.08
velocity.y = -velocity.y * energy_loss # Reverse y-velocity with energy loss
if abs(velocity.y) < 0.25: # Stop bouncing if energy is too low
velocity.y = 0
That seems to be working well. The issue is with collision. I’ve tried every combination of area and collision nodes I’ve read about, but no matter what I try the ball phases right through the paddle. Currently I have the paddles set up as Node3D > RigidBody3D > CollisionShape3D. The collision shape is a cylinder that matches the paddle face size.
In the ball’s script I have:
@export var paddle_player: Node3D
and
if body == paddle_cpu or body == paddle_player:
# Reverse the Z velocity on paddle hit
velocity.z *= -1
And I’ve tried what feels like 50 other variations on this, yet nothing seems to work. If someone could recommend the most simple way to do this, I don’t mind what way but whatever is simple.
I should also note that I have a player paddle and a cpu paddle that tracks the ball’s x and y coords.
Thank you for the help!