Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity different physics behaviour in different screen sizes

I'm working on a 2D top-down open-world game in which there is a character who can be moved by keyboard functions. The movement is caused by Rigidbody.AddForce().
The problem is that the moving speed is not the same in different screen sizes.

Here's the simple code:

void FixedUpdate()
{
    if (Input.GetButton("Move"))
        rigidbody.AddForce(transform.forward * speed);
}

The character's mass is the same, the float speed is the same but yet, after I switch the game view to full screen, obviously the character moves faster. (Which is odd, and shows that it's not a performance problem.)
I've tried to test the standalone build, everything's fine there (however it seems a bit slower in android build.) but I need to have a common speed in the editor because I have to design levels that depend on the timing and the timing depends on the speed.

like image 780
Bamdad Avatar asked Jan 27 '23 13:01

Bamdad


1 Answers

Physics works in WorldSpace and has nothing to do with ScreenSpace, so your problem is beyond what it seems to be. The performance drop on android is expected, but in standalone, make sure you use FixedUpdate for physics operations (which you do here) and make sure nothing is causing FixedTimeStep to change during the game by any chance.

like image 85
soheilgh Avatar answered Jan 29 '23 04:01

soheilgh