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.

godotengine.org | Twitter

0 votes

I've been making a BBTan Clone in Godot where balls are implemented as KinematicBody2D. I have a Board class (which extends Node2D) that holds other objects as children (boxes, triangles, player, balls, etc.). The feature I want to have is to be able to scale the Board so that I can fit it to the screen (in case of different screen resolutions, number of rows/columns).

I've tried to just change the scale of the Board node itself. Although it visually looks good (everything is scaled as it should), it introduces a bug with the movement of balls. No matter the scale of the Board, balls always move with the same speed on the screen while their movement should depend on the scale of the Board (so that the gameplay is the same, that's why I put balls as children of the Board).

I found out that move_and_collide() method on KinematicBody2D uses the global transform to handle the movement so it's not affected by the parent's transform.

It looks like a killer to me. I think that the only way I can fix it is to change the positioning of children rather than changing the transform of their parent. But that feels bad because I thought it would be automatically handled by the engine.

Is there any other way to handle it?

in Engine by (27 points)

1 Answer

0 votes

I'm not sure if this is the right way to do it but I decided to transform velocity vector using global transform before passing it to move_and_collide() method:

func _physics_process(delta):
    var rel_vec = (velocity * global_scale).rotated(global_rotation)
    var collision_info = move_and_collide(rel_vec * delta)

This seems to work fine.

by (27 points)
edited by
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.