How to scale movement using move_and_collide

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

Godot version 3.2 BETA 1


I am trying to find a way to scale the movement of a KinematicBody2D so that it behaves the same on different screen sizes. Currently, I am finding that a KinematicBody2D moves at different speeds depending on the screen size.

For example, I am creating a pixel art game where my “game” resolution is lower than the screen resolution. My game is 288w x 512h (portrait). On a mobile screen of 1080 x 1920, my artwork needs to be scaled up by 3.75 times. I could do this by simply scaling the viewport, but I find this gives choppy movement since the object is moving in steps of 3.75 pixels (maybe 4 with pixel snapping). Instead, I have chosen to scale the artwork and maintain the screen resolution. This gives really smooth movement, but the results are inconsistent.

I thought that simply multiplying the vector by the scaling factor would result in move_and_collide behaving the same on all screens but it does not. A test object moving from one side of the screen to the other, is significantly faster on the 288x512 window within Godot, than the 1080x1920 mobile device screen.

In essence, I need the object to move 3.75 times faster on the mobile test device, than it does in the Godot test window because it has to cover 3.75 times more distance in pixels. If anyone has any thoughts on how I can do this, or has an idea where I may have tripped up, I really would appreciate it.

Thanks for taking the time to read this essay! :slight_smile:

Good day! This is an interesting idea.

Berta | 2021-12-27 00:50

:bust_in_silhouette: Reply From: i_love_godot

It turns out, you can scale the movement… but you need to use move_and_collide inside the _physics_process(delta) function and NOT the _process(delta) function.

My mistake, I need to read the docs more carefully XD