Godot Version
3.5.1
Question
Hello all,
I am a newbie here and to Godot in general. I have hunted for a answer to this and have not found one but perhaps I was just not using the correct search terms. In any case any help would be appreciated.
I have a section of my game with very simple functionality where a ball is rolling around in on an otherwise blank phone screen. The physics need to feel correct to the phone in the users hand.
I am using “apply_impulse” to a RigedBody2D (the ball) with the following formula:
Vector2(Input.get_accelerometer().x * speed, -Input.get_accelerometer().y * speed
I am not sure how to set the speed so that it works on different devices. I had been using iPhones as test devices (an iPhone 11 and an iPhone 13) and a speed of 30 worked well. But when I tested on an old android device it was WAY to fast to be useful. I had to dial the speed down to 3 to get a comparable feel.
I am looking at my equation and I am not sure if the problem is the “get_accelerometer” of the equation or the “speed” variable.
If it is the “get_accelerometer” then does that mean that the accelerometers on android devices return a different kind of number than the accelerometers on iOS devices (for example the decimal place moved over one)? In which case do I need to try and set the speed number based on operating system? (Perhaps setting the speed based on the results of OS.get_name()?)
If it is the “speed” variable does that mean that I need to look at pixels/sec and screen resolution for a fix? The android device I am using has a 720 x 1560 screen as opposed to the 1170 x 2532 screen of the iPhone 13. I can imagine a solution that queried the device on the screen size and resolution and set the speed based on that, and that does seem like it might be part of my problem, but the screen resolutions are are 1.6X different not the 10x different that I am having to change the speed variable.
Does anyone have any insight into this? Or solutions that have worked for them? Or recommended strategies? (Or even recommended code that they would use to set the speed or modify the accelerometer input based on screen size or OS?)
Thanks so much for any thoughts!
Best,
NB