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 physicsprocess(delta):
var velocity = Vector2.ZERO
if Input.isactionpressed("uiup"):
velocity.y -= 1
if Input.isactionpressed("uidown"):
velocity.y += 1
moveandslide(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 physicsprocess(delta):
var collisionobject = moveandcollide(velocity * speed * delta)
if collisionobject:
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.