- Home /
What's the difference between Update and FixedUpdate
I ask this because I have this code
void Update ()
{
piso = Physics2D.OverlapCircle (gdchk.position, gdradius, 1 << LayerMask.NameToLayer("suelo")); //es un booleano que sera true o false si toca el suelo o no
//Debug.Log (rigidbody2D.velocity.y);
//if (piso || (Mathf.Floor(Mathf.Abs(rigidbody2D.velocity.y)) == 0 && transform.position.y < 7.1))
//if (piso || (rigidbody2D.velocity.y == 0 && transform.position.y < 7.1))
if (Mathf.Floor(Mathf.Abs(rigidbody2D.velocity.y)) == 0 && transform.position.y < 7.1)
{
// Debug.Log (Mathf.Floor(Mathf.Abs(rigidbody2D.velocity.y)));
// Debug.Log (transform.position.y);
//elemento.rigidbody2D.isKinematic = true;
suelo = true;
Semillero2.pieza = false;
}
//Debug.Log (suelo);
}
with this code the last two variables are no receiving the values I want, but the same code with FixedUpdate instead, the value of the variables is received, why? What does Update and what does FixedUpdate do?
What two values? I don't see anything that would variate based on Update or FixedUpdate.
Searching for "unity update fixedupdate" will gives lots of explanations.
I mean, the values for "suelo" and for "Semillero2.pieza", with FixedUpdate the assignment is respected and with FixedUpdate don't
Answer by tanoshimi · Feb 22, 2015 at 08:32 AM
Update runs once every frame while the game is running. It runs at a variable rate, as often as your computer can process. It is the core of every game loop.
FixedUpdate runs once every iteration of the physics loop, which is an amount of time you set (say, 30 times per second, or 50 times per second). So it may be called more or less often than Update (), not necessarily in sync with it. It is used for physics calculations that need to be simulated at a certain rate to ensure consistency.