Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vitor-Ferreira · Feb 03, 2014 at 11:03 PM · physicsupdatefixedupdate

FixedUpdate is used only for physics objects. How exactly?

So, is it ONLY used for physics objects, or there are exceptions? Here, take this code that I made, where I try to rotate the camera around a cursor by 90 degrees after user input, for instance:

 using UnityEngine;
 using System.Collections;
 
 public class CameraScript : MonoBehaviour {
     public Transform cursor;
 
     private bool rotate = false;
 
     private float alreadyRotated = 0;
 
     void Rotate () {
         transform.RotateAround(cursor.position, Vector3.up, 90 * Time.deltaTime);
 
         alreadyRotated += 90 * Time.deltaTime;
     
         if(Mathf.Approximately(alreadyRotated, 90))
         {
             rotate = false;
             alreadyRotated = 0;
         }
     }

     void Start () {
         transform.position = new Vector3(8, 3, 12);
         transform.LookAt(cursor);
     }
 
     void Update () {
         if(Input.GetKey("1"))
         {
             rotate = true;
         }
     }
 
     void FixedUpdate () {
         if(rotate)
         Rotate();
     }
 }


I'm not dealing with physics here, right? If I do call this inside a Update(), however, the Camera never stops rotating, while inside a FixedUpdate() it does (this is what I want). I do get it, however, that this is because FixedUpdate gives me more precise results, but I was just questioning myself... Is it right to limit the use of FixedUpdate to RigidBody use, only? I've seen this being said more than a couple of times already... Please enlighten me, guys! Thanks :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Feb 03, 2014 at 11:05 PM

Did you try searching? http://answers.unity3d.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vitor-Ferreira · Feb 03, 2014 at 11:16 PM 0
Share

Hi tanoshimi, thanks for the answer. I've actually read that post sometime ago. He basically says what I'm questioning:

It's for this reason that FixedUpdate should be used when applying forces, torques, or other physics-related functions - because you know it will be executed exactly in sync with the physics engine itself.

Whereas Update() can vary out of step with the physics engine, either faster or slower, depending on how much of a load the graphics are putting on the rendering engine at any given time, which - if used for physics - would give correspondingly variant physical effects!

I may be wrong, but the rotation I'm perfor$$anonymous$$g, can be considered a physics function? Because it (my rotation) only works with FixedUpdate. This is the point I'm not getting...

avatar image Eric5h5 · Feb 03, 2014 at 11:34 PM 0
Share

It's not a physics function. The reason it won't work in Update is because you're using $$anonymous$$athf.Approximately, which is only for very tiny values. It's highly unlikely that you will get a result that's almost exactly 90.

avatar image Vitor-Ferreira · Feb 03, 2014 at 11:36 PM 0
Share

Then this is a special scenario where FixedUpdate will work and Update won't? Thanks for the answer, Eric5h5!

avatar image Eric5h5 · Feb 03, 2014 at 11:47 PM 0
Share

No, FixedUpdate isn't appropriate, and can still fail. You should use logic that doesn't depend on two float values being equal (or nearly so).

avatar image Vitor-Ferreira · Feb 03, 2014 at 11:54 PM 0
Share

I see. Thanks. Any suggestions as to what I should use to make a camera move 90 degrees around other object, after a user presses 1?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Game not running properly on slow machines (low fps) 1 Answer

Supplying Input from Update To FixedUpdate 1 Answer

Is there an equivalent of Time.frameCount for physics updates? 1 Answer

Does AddForce use Time.deltaTime or TIme.fixedDeltaTime or it depends on whether it is being used in Update() or fixedUpdate()? 2 Answers

FixedUpdate vs. Update for instantaneous ForceMode's 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges