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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by SirMalarkey · Feb 26, 2015 at 02:45 PM · movementphysicstimedeltatimespring

When to apply delta time for framerate independence.

I have been writing a bunch of physics related code for my parkour game lately. Before now I had been using all this code in FixedUpdate, but do to efficiency reasons I would now like to achieve framerate independence via the use of Time.deltaTime. The problem is whenever I use it, it never seems to work properly. An example piece of code I would like to use Time.deltaTime on would be:

 using UnityEngine;
 
 public class c_Physics
 {
     static public Vector3 Vector3_Spring(Vector3 current_vector, Vector3 target_vector, Vector3 last_delta, Vector3 stiffness, Vector3 damping)
     {
         if (target_vector == current_vector)
         {
             return Vector3.zero;
         }
         Vector3 distance = target_vector - current_vector;
         Vector3 delta = Vector3.Scale(distance, stiffness / 100f) + last_delta;
         delta -= Vector3.Scale(delta, damping / 100f);
         return delta;
 
     }
 }

// Next piece of code using UnityEngine;

 public class Vector3_Spring_Test : MonoBehaviour 
 {
     Vector3 current_vector; // current location of the spring.
     Vector3 target_vector; // where it needs to be.
     Vector3 last_delta = new Vector3(0.0f, 0.0f, 0.0f); // How much force was addded to the spring last frame
     Vector3 stiffness = new Vector3(1f, 1f, 1f); // how fast it aproaches target
     Vector3 damping = new Vector3(0f, 0f, 0f); // how fast it stops moving
 
     public void Update()
     {
         current_vector = transform.position;
         target_vector = new Vector3 (0.0f, transform.position.y, transform.position.z);
         last_delta = c_Physics.Vector3_Spring(current_vector, target_vector, last_delta, stiffness, damping);
         transform.position += last_delta;
     }
 
 }
 

No matter where I apply Time.deltaTime in this example I always end up with issues, such as the frequency of my spring will match across framerate, but the amplitude will not, or the spring will just snap to its origin without oscillating at all. Do to the large amount of physics and movement based math in my game I would really like to figure deltaTime out.

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 hexagonius · Feb 26, 2015 at 02:58 PM

Think of deltaTime as of “per second“. Whatever you multiply it with happens per second. But only in Update, it's not needed in FixedUpdate as long as you manipulate velocity for example, because that's already per second by nature.

Comment
Add comment · Show 1 · 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 SirMalarkey · Feb 26, 2015 at 03:06 PM 0
Share

I know that, but I cannot figure out what to multiply it by in my example. I've done every variation possible, but when I go to quality and switch between simple and fantastic, the results are always different or not what was intended.

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

Movement using Time.deltaTime not working on Fast mac 3 Answers

Force mode and delta timing 1 Answer

(NEW USER) 2D character movement is laggy 0 Answers

RigidBody.MovePosition seems jerky in movement 0 Answers

move player to its rotating direction? 2 Answers


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