Unity different physics behaviour in different screen sizes
Asked Answered
C

2

5

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.

Ciceronian answered 26/3, 2019 at 20:23 Comment(1)
It is very curious, as there should be nothing like that in Unity. Screen size and physics are unrelated. I suggest you do like that: print the actual value of rigidbody velocity and maybe forces in real time and see whats actually going on. Quickest way to do it is probably using legacy GUI: void OnGUI(){ GUI.Label(new Rect(10, 10, 100, 20), rigidbody.velocity.ToString()); }Worsham
I
8

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.

Isleana answered 4/4, 2019 at 17:34 Comment(1)
Yea, thanks for the answer, I found out that there was a Update method in a driven class which was effecting on the rigidbody. Thanks for reminding me of FixedUpdate.Ciceronian
P
3

did you try to multiply your speed with Time.fixedDeltaTime ? If it didn't work, try platform dependent compilation:

    #if UNITY_STANDALONE_WIN
        //do something
    #elif UNITY_ANDROID
        // do something
    #endif
Pheon answered 27/3, 2019 at 1:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.