Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RotateTowards and MoveTowards

Discussion in 'Scripting' started by MathewHI, Jun 1, 2021.

  1. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Should these be used in Update or FixedUpdate?
     
  2. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    Either. FixedUpdate will be ticked at a fixed frequency (you can specify) that sync's it to physics updates. Update will be called one per frame. FixedUpdate can be called multiple times a frame.

    In either case, you should multiply any motion by Time.deltaTime so that everything is frame/physics rate independent.
     
    MathewHI likes this.
  3. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    I am multiplying it by Time.deltaTime and I tried both Update methods to see the difference and the movements look the same to me
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Depends entirely on what you're moving or rotating. FixedUpdate is for controlling rigidbodies, Update is for moving everything else like visual fx.
     
  5. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    You can move anything in either, but there are different ramifications.

    Anything interacting with physics should be done in FixedUpdate yo keep your simulation in sync with the internal physics update. Otherwise you might get some jitter or other artifacts.

    Other than that, Update is typically where you do simple object updates.