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 BasomtiKombucha · Feb 28, 2014 at 11:55 AM · physicsrigidbodyupdateplatformerfixedupdate

Rigidbody character and Update() function

So in official Unity's 2D Character Controllers tutorial ( http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers ) they made their character out of a physics2D rigidbody. That's kind of cool, but if they want to move this character, they must do it in an FixedUpdate() function (since it's a rigidbody).

But what about the DeltaTime stuff? The movement can now get ahead or behind the frame rate, right? Can't this be fixed? Does it mean that you can either have a smooth game, or a physics-based game, but not both?

Comment
Add comment · Show 2
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 TurboHermit · Feb 28, 2014 at 12:19 PM 0
Share

I don't really understand. FixedUpdate still makes your game smooth, it just runs all code within it less times, but it doesn't impact your frame rendering.

avatar image BasomtiKombucha · Feb 28, 2014 at 03:20 PM 0
Share

Yes but, since the rendering is done in the Update() function, it can de-smooth the movement of objects by rendering them in different positions for different amounts of time. Example: Let's say that my FixedUpdate runs every second. We have an object that gets translated by 5 units with each FixedUpdate call. Now, the Update() function, which renders the screen, gets called at random intervals. Let's say that in this case, it gets called at 0.1, 0.9, 1.4 and 2.0 in-game seconds. This means that during the first frame (0.1), our object is at position 0. During the second frame (0.9), our object is still at position 0, since we only move it in the first FixedUpdate call (which will be called in 1.0). During the third frame (1.4), our object has finally moved and is now in position 5. During the fourth frame (2.0), our object has moved once again and is now in position 10.

So, we have an object that should move in constant speed, but it doesn't appear like that because it sometimes takes him more and sometimes less frames to move (it took him two frames to move from 0 to 5, but only one frame to move from 5 to 10).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Feb 28, 2014 at 12:18 PM

In FixedUpdate you use Time.fixedDeltaTime instead of Time.deltaTime.

Comment
Add comment · Show 2 · 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 BasomtiKombucha · Feb 28, 2014 at 03:21 PM 0
Share

I don't understand, how does this fix anything? I might have explained myself incorrectly - see my reply to Danzou above.

avatar image whydoidoit · Feb 28, 2014 at 03:25 PM 0
Share

That's not how physics works. The game has a flexible frame rate, every time a frame starts it calls FixedUpdate the number of times necessary to catch the physics time up to the frame time. If your frame rate is super high, you can decrease the time between physics steps if you like so that it runs frequently - if you run at 100 fps you should decrease the physics time to make sure that you keep running the physics step often enough etc. (otherwise it would only run every other frame with the standard setting)

Inside FixedUpdate you use fixedDeltaTime to smooth out your movements to make them frame rate independent.

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

22 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 avatar image avatar image

Related Questions

Is it okay to use ForceMode.VelocityChange in Update()? 1 Answer

2D 360 degress platformer example needed 0 Answers

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

AddForce in Update 1 Answer

Applying Forces, independent of Frame Rate? 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