Please help going insane

this is from Unity Learn Challenge 3 - Balloons, Bombs, & Booleans

after getting this weird issue

i deleted everything and started just with the balloon and set its force value to 10 let it fall on the ground level and it would go up slowly.

after changing an object position i.e camera or background.

i press play, let the balloon fall to the ground level and the balloon force is CRAZY DIFFERENT even though its value is at 10.

the script is just a simple addforce script with nothing else on it

Not sure why but i cant play the video in this forum please visit the youtube site if you have the same problem youtube.com/watch?v=N57x9bjI3_8

Show the script that affects the balloon.

public class PlayerController : MonoBehaviour
{
    private Rigidbody playerRb;
    public float floatForce ;

    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            playerRb.AddForce(Vector3.up*floatForce, ForceMode.Force);
        }
    }
}

Maybe use GetKeyDown. Now you will add force every frame as long as you hold the spacebar

Also use code tags if you post code

getkeydown was my first attempt writing the code,so i tried different things like getkey and left it there since it was all the same and giving me that weird issue

try adding forces inside FixedUpdate

1 Like

Definitely this.

If you do an AddForce() with -Physics.gravity * mass it will only hover perfectly if that code is inside of FixedUpdate()

Otherwise there will be variation.

1 Like

Thanks! this was true, however the challenge itself never thought us to put physics related code into fixedupdate but their project did not have the above issue putting the code in normal update. so its weird,especially for a beginner that doesn’t know about this.

These discussions might help you cement why exactly:

Two good discussions on Update() vs FixedUpdate() timing:

https://jacksondunstan.com/articles/4824

https://johnaustin.io/articles/2019/fix-your-unity-timestep