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 djfluffwug · Oct 08, 2011 at 05:56 AM · rigidbodyframeratetime.deltatimeslow

Time.deltaTime really slow

I have been using addforce with my rigidbody but realised that on slower computers, you won't get the same force. I then tried to impliment Time.deltaTime with my addforce script but the rigidbody then started moving really really slow in the game and had terrible acceleration. I don't know what to do. Here is my script:

  var maxVelocity : float = 5;
  function FixedUpdate () {
      if (Input.GetKey ("down")) 
          {
               rigidbody.AddForce (Vector3.forward * -0.2 *

Time.deltaTime); }

              if (Input.GetKey ("up")) 
          {
               rigidbody.AddForce (Vector3.forward * 0.2 *

Time.deltaTime); }

                      if (Input.GetKey ("left")) 
          {
               rigidbody.AddForce (Vector3.left * 0.2 * Time.deltaTime);
          }
                      if (Input.GetKey ("right")) 
          {
               rigidbody.AddForce (Vector3.right * 0.2 *

Time.deltaTime); }

              var velocity = rigidbody.velocity;
      if (velocity == Vector3.zero) return;
      var magnitude = velocity.magnitude;
      if (magnitude > maxVelocity)
      {
          velocity *= (maxVelocity / magnitude);
          rigidbody.velocity = velocity;
      }
  }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by syclamoth · Oct 08, 2011 at 06:00 AM

The reason it seems to be really slow, is that when you changed to using Time.deltaTime, you forgot to multiply all your values by your expected framerate!

To elaborate- if you don't use Time.deltaTime, it adds a given force every single frame. When you multiply by Time.deltaTime, it normalises everything such that it instead adds the amount of force per frame that it would add up to that amount over a single second. So, under normal cirumstances, you would have to multiply all your other values by about 60 (assuming 60 frames per second was what you were getting in the first place) to replicate the original behaviour.

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 djfluffwug · Oct 08, 2011 at 06:15 AM 0
Share

Thankyou! This worked perfectly. You don't know how long I have been stuck trying to figure out such a simple thing. I nearly gave up making my game.

avatar image syclamoth · Oct 08, 2011 at 06:19 AM 1
Share

Never give up! Tricky is the opposite of impossible!

avatar image
0

Answer by Azound · Oct 08, 2011 at 06:00 AM

Have you made sure that maxVelocity = 5 isn't too low for your game? Try setting it to 500 and see if that makes a difference.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Once for all... is Time.deltaTime good or bad with Input.GetAxis? 1 Answer

hi-polys ??? frame lag when instantiating prefab of rigidbodys 1 Answer

SmoothDamp smoothTime ignored! 1 Answer

Rigidbody y velocity is stuck on 0, gravity is not turned off. 2 Answers

unity freezes repeatedly 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