![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Kriecheer |
Hello everyone, I’d been following a tutorial on how to make a basic pong game but wanted to try changing the typical bars for rounded shapes.
Now I’m facing the problem that whenever the ball hits the “player” it will push them slightly each time. I’m not sure if I did something wrong with the code or if changing the shape had something to do with it.
This is the code for my “player”:
extends KinematicBody2D
var speed = 400
func _physics_process(delta):
var velocity = Vector2.ZERO
if Input.is_action_pressed(“ui_up”):
velocity.y -= 1
if Input.is_action_pressed(“ui_down”):
velocity.y += 1
move_and_slide(velocity * speed)
This is the code for my ball:
extends KinematicBody2D
var speed = 600
var velocity = Vector2.ZERO
func _ready ():
randomize()
velocity.x = [-1, 1][randi () % 2]
velocity.y = [-0.8, 0.8][randi () % 2]
func _physics_process(delta):
var collision_object = move_and_collide(velocity * speed * delta)
if collision_object:
velocity = velocity.bounce(collision_object.normal)
I tried several things like changing the “player” to RigidBody2D and StaticBody2D but I know this is not optimal for what I’m trying to do.
Any help is appreciated, thanks in advance.