How do I deal with KinematicBody2D using global_transform during move_and_collide()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CosmicKid

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?

:bust_in_silhouette: Reply From: CosmicKid

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.