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 gamedev098 · Feb 01, 2014 at 08:02 AM · deltatimespike

Sudden spike, delta time

I am making a game in which i multiply the SPEED with deltaTime. The value is mostly normal but at times it shoots up to 2x the normal value. Maybe its because of the frame rate? Normally the value is between 7.9 to 8.3 , but the spike takes the value up to 17.

Is there any way to fix it? I am doing this in the update() method.

Comment
Add comment · Show 5
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 getyour411 · Feb 01, 2014 at 08:05 AM 0
Share

Time.deltaTime is the time in seconds it took Unity to complete the last frame; 7.9 or 8.3 or 17 is way way out of whack. When you play your game, what's your FramesPerSecond when this happens and can you show the code for the relevant part where you are doing your calcs

avatar image Benproductions1 · Feb 01, 2014 at 09:48 AM 0
Share

7.9 means that the last frame took about 8 seconds to complete... What toaster are you running this on?

avatar image gamedev098 · Feb 01, 2014 at 08:00 PM 0
Share

Here's the code

     void Update () {
         isPressed  =  false;
         
        if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow))
         {
             isPressed = true;
             xSpeed -= (SPEED_STEP*Time.deltaTime);
         }
         if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
         {
             isPressed = true;
             xSpeed += (SPEED_STEP*Time.deltaTime);
         }
 
             if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.UpArrow)){
                       // HERE IS THE PROBLE$$anonymous$$
                             print("jump speed : "+(jumpSpeed*Time.deltaTime));
                 ySpeed += (jumpSpeed*Time.deltaTime);
             }
         
         ySpeed -=(gravity*Time.deltaTime);
         
          if ($$anonymous$$athf.Abs(xSpeed)<1&&! isPressed) {
                 xSpeed=0;
          }
         xSpeed *=hFriction;
 
         checkCollisionX();
         checkCollisionY();
     }

This is the code, its basically for a platformer game. the value of SPEED_STEP = 40; jumpSpeed = 500; gravity = 15;

The FPS is between 73-88

avatar image GTX Titan · Feb 01, 2014 at 09:55 PM 0
Share

I don't see any problems with it, but you could try to put the if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.UpArrow)){

 // HERE IS THE PROBLE$$anonymous$$

 print("jump speed : "+(jumpSpeed*Time.deltaTime));

 ySpeed += (jumpSpeed*Time.deltaTime);

 }else if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.UpArrow)

 ySpeed -=(gravity*Time.deltaTime);

But I don't think this will solve your problem. Why not use built in colliders and physics?

And for my answer:

     ySpeed -=(gravity*Time.deltaTime);
 
 if(ySpeed > maxValue) //for the positive values
     ySpeed = maxValue;
 else if(ySpeed < $$anonymous$$Value) //for the negative values
     ySpeed = $$anonymous$$Value;
 
     if ($$anonymous$$athf.Abs(xSpeed)<1&&! isPressed) {
     
     xSpeed=0;
     
     }
     
     xSpeed *=hFriction;
      
     checkCollisionX();
     
     checkCollisionY();
avatar image gamedev098 · Feb 02, 2014 at 02:22 AM 0
Share

There character controller has a problem according to this( http://www.gamasutra.com/blogs/YoannPignole/20131010/202080/The_hobbyist_coder_1_2D_platformer_controller.php ) and I want to give the character cartoony physics so thats why.

What if i use fixed Delta time, will it fix my problem? if so, any consequences ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GTX Titan · Feb 01, 2014 at 10:01 AM

You could make an if statement to check if it's too much and then assign it a max value if it is. if(moveAmount > maxValue) moveAmount = maxValue

I am not sure what kind of functionality you need, but if you want it to move at the same speed you want this: moveAmount = speed*Time.deltaTime;

The spikes are caused by framerate since it is moving at the same speed but you just see less frames of it. As for the value jumping between 8-17 I'm guessing your speed value is somewhere around 300-1000.

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

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

Is SimpleMove() framerate-independent under the hood? 1 Answer

Shouldn't deltaTime be defined as the 1 over the time interval between two frames? 2 Answers

How to fast forward time (or just skip it) properly? 2 Answers

Why will this timer not count down? 1 Answer

Transform.position can't be changed smoothly. 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