The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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
velocity.y += 1
moveandslide(velocity * speed)

This is the code for my ball:

extends KinematicBody2D

var speed = 600
var velocity = Vector2.ZERO

func _ready ():
velocity.x = [-1, 1][randi () % 2]
velocity.y = [-0.8, 0.8][randi () % 2]

func physicsprocess(delta):
var collisionobject = moveandcollide(velocity * speed * delta)
if collision
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.

in Engine by (12 points)

1 Answer

0 votes

You definitely want to use a static body, read documentation here:

If you want to make more smooth movement with slide functions you could use a rigid body with axis locked also:

by (134 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.