RigidBody or KinematicBody?

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

Hello,

I am currently in the process of making my very first game(for Android phones). The basic idea is there is ball with initial direction and speed, going up at some angle, not falling, and it bounces off the edges of the screen. The player tilts their phone and the ball’s bounce direction depends on the incline of the phone. The picture shows what I want to happen if the phone is perfectly upright. If it is tilted the bounce angle would obviously changebasic bouncing off the edges f the screen

I am not sure whether to use RigidBody2D or KinematicBody2D. I implemented it with KinematicBody at first, but I don’t know how to change the speed, while keeping the same direction (the ball should go faster and faster as level up). But since the ball is actually not controlled by the player directly, I thought maybe RigidBody. But I cannot work out the angular and linear velocities, is there a way to change the speed of movement without changing the direction. I just need to control the direction/angle and speed of the ball. Any advice would be greatly appreciated, as I feel a little lost. Thank you!

:bust_in_silhouette: Reply From: kidscancode

KinematicBody2D is fine for this. You rarely need a rigid body for most games, especially if you’re just doing basic collision with static objects.

You should have some sort of velocity vector, which you are using in the move() function. To increase the speed, you just scale that vector: velocity *= 2 for example. This is basic vector math, so if you’re not familiar, I recommend a quick review - Khan Academy has a good one, for example.

Bouncing is super easy, btw, if you just use the Vector2 reflect() method:

if is_colliding():
    var n = get_collision_normal()
    motion = n.reflect(motion)
    vel = n.reflect(vel)

I wrote an overview of K2D collision here if you want more detail: Godot 101 - Part 13: KinematicBody2D Collisions Done Right · KCC Blog