Make kinematic bodies bounce off other kinematic bodies

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By arkalain
:warning: Old Version Published before Godot 3 was released.

Hello all, I have been testing godot a bit for the last 2 days. So far I’m liking it.

I have been trying to create a small pong-like game where I have a circle made of off many rectangles.

Every rectangle has a rectangle collision shape, and they are rotated to create a circle.
The ball is created with a circleshape.

The problem Im having is that the ball only “bounces” correctly when colliding with either the top or the bottom rectangle, when it hits any other it kind of “throws” the ball out of the circle

Kind of hard to explain so here’s a gif showing what I mean:

Here’s the code for the ball:

extends KinematicBody2D

const speed = 50
var direction = Vector2(0, -1)
var paddles = []

func _ready():
	set_fixed_process(true)

func _fixed_process(delta):
	var velocity = direction * speed
	var motion = velocity * delta
	motion = move(motion)
	
	if (is_colliding()):
		var colliding_paddle = get_collider()
		var paddle_color = colliding_paddle.get_color()
		get_node("background").set_modulate(paddle_color)
		
		var normal = get_collision_normal()
		motion = normal.slide(motion)
		move(motion)
		
		#new direction, for now take the normal
		direction = normal
	
	get_node("Label").set_text(str(direction))

Really lost here, not sure how to approach fixing this … would appreciate any help to make it work :slight_smile:

Set collisionshape to visible in editor perhaps you see something not be correct.
In your gif, it looks like your ball curves. Correct?

puppetmaster- | 2016-04-11 08:44

the ball is not curving, it’s following a straight line. It just looks like its curving because of the circle rotation.

Also, the collision shape seems to always be where it is supposed to (I did try enabling them and couldn’t find anything strange about it).

I do think it has more to do with the normal.slide(motion) line…I’m just not very sure how to fix it , if I don’t apply the slide, the ball will stop moving after the first collision it detects

arkalain | 2016-04-11 19:34