- Home /
Climb animation in Update or FixedUpdate or LateUpdate?,
It's my code.
public bool PlayerCanClimbTheLadder; public Animator animator;
public void ClimbAnimation(){
if (PlayerCanClimbTheLadder && Input.GetKey (KeyCode.W)) {
animator.SetBool ("Ladder",true);
GetComponent<Rigidbody2D> ().isKinematic = true;
transform.Translate (new Vector2 (0, 2 * Time.deltaTime));
}
} Is there any difference If I use this code in update or fixedUpdate or lateUpdate ?
,
Answer by SohailBukhari · Jul 26, 2017 at 06:21 AM
You should check that in LateUpdate that occurs after the internal animation update in each loop.
Input should be in Update() so that there is no chance of having a frame in which you miss the player input.
FixedUpdate used where we need to apply continuous forces. Physics calculations should be in FixedUpdate(), so that they are consistent and synchronized with the global physics timestep of the game.
what about transform.Translate (new Vector2 (0, 2 * Time.deltaTime));?
I think if this code checks in LateUpdate or FixedUpdate the Result might be difference .???
How can I get inputs in update and place animations in LateUpdate and put physics in FixedUpdatE????
the result is the same if you use
transform.Translate (new Vector2 (0, 2 * Time.deltaTime));
inside FixedUpdate(), LateUpdate() or Update()
. in unity manual it says
When called from inside $$anonymous$$onoBehaviour's FixedUpdate, returns the fixed framerate delta time.
if you want to update the movement in FixedUpdate()
you can keep a separate variable in your script to store the state of your animation. In FixedUpdate() you can check that state variable and do the movement
dude I made a test and realized that if you use transform.Translate in update or FixedUpdate the result is definitely different.
I made a time-=time.FixedDeltaTime;//
then put transform.Translate in update and then in FixedUpdate. after 5 seconds y position in Update was between 20and 22, but when I used that in FixedUpdate and everyTime it returned 21.5.
the problem is that I don't know how to get inputs in Update and then move my character in FixedUpdate and place animations in LateUpdate
Your answer
Follow this Question
Related Questions
how to achieve a LateFixedUpdate effect 5 Answers
What's the execution order of Updates of different objects? 1 Answer
Should we check animation condition in Update or FixedUpdatE? 3 Answers
Coroutines vs Update/FixedUpdate/LateUpdate 2 Answers
Should terrain detail data be set on update, fixedupdate, lateupdate or coroutines? 0 Answers