0 votes

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!

in Engine by (15 points)

1 Answer

+3 votes

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: http://kidscancode.org/blog/2017/06/godot_101_13/

by (20,895 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 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 webmaster@godotengine.org with your username.