Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Scene load additive and Physics issues?

Discussion in 'Scripting' started by itisMarcii_, Sep 6, 2022.

  1. itisMarcii_

    itisMarcii_

    Joined:
    Apr 5, 2022
    Posts:
    107
    Hey, I am currently running into an issue which i can not entirely get my head around.

    I have a simple Jump method that performs that code snippet when the Jump KeyDown gets tracked:

    Code (CSharp):
    1.     if (Physics.Raycast(transform.position - _PositionShift, Vector3.down, out var hit, _GroundCastLength, _Mask))
    2.     {
    3.       if (hit.collider.tag == "Ground") gravityValue = _JumpForce;
    4.     }

    With the Gravity kinda performing constantly like that:

    Code (CSharp):
    1. gravityValue += _Gravity * _DeltaTime * weight;
    2.  
    3.     if (gravityValue <= _Gravity) gravityValue = _Gravity;
    4.     characterController.Move(Vector3.up * gravityValue * _DeltaTime);

    Overall no issues here. Now, when i load my Menu (which is in a separate Scene) additive, the Jump wont perform like it normally would. It jumps a much lesser high than it is supposed to.

    So here is my question, does the LoadSceneAsync("MenuScene", LoadSceneMode.Additive); mess with the physics in any way?
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    No, it does not :)
     
    MelvMay likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Physics doesn't know about that stuff. All it knows are physics components that generate physics objects. When loading another scene, if you're loading physics objects then they may affect what you're doing depending on what they are. If it's a menu then no, you're looking in the wrong place.

    Maybe you've just created a frame-dependent movement doing moves per-frame or something. The frame-rate changes, so does your physics.
     
    itisMarcii_ likes this.
  4. itisMarcii_

    itisMarcii_

    Joined:
    Apr 5, 2022
    Posts:
    107
    Yes the Frame difference was messing around with my Input Prediction. Currently for simplicity i used a frame dependet movement system. Despite locking the framerate to 32, the drop seems significant enough to reach the .001 tolerance.
     
    MelvMay likes this.