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 /
  • Help Room /
avatar image
0
Question by MarcoZan · Nov 17, 2020 at 10:23 AM · updatefixedupdatetimestepfrequency

Change Fixed Timestep?

Hello everyone, i have been using unity for a few months (i apologize in advance for the inexperience) to create a driving simulator, so as to obtain information on the trajectory traveled, speed, acceleration etc.

In the script i made i used a FixedUpdate, and therefore the frequency is equal to 50 Hz (0.02).

I would like to change the frequency and i have tried both by changing the "Fixed Timestep" in the unity settings, and by introducing "Time.fixedDeltaTime" in the FixedUpdate. But in both cases there are repercussions on the physics of the vehicle, which i can no longer control.

Any suggestions on how to fix this?

Thanks in advance

 using UnityEngine;
 using System.IO;
 
 public class Traiettoria : MonoBehaviour
 {
     public GameObject CAR;    
     public Rigidbody Car;
 
     public float Posx;
     public float Posy;
     public float Posz;
     public float TIME;
     public float SPEED;    
 
     void Start()
     {      
 
         Posx = CAR.transform.position.x-98;
         Posy = CAR.transform.position.y;
         Posz = CAR.transform.position.z;
 
         TIME = Time.time;
 
         SPEED = Car.velocity.magnitude;
 
         Time.fixedDeltaTime = 0.5f;        
 
     }  
 
 
     void FixedUpdate()
 
     {   
         Posx = CAR.transform.position.x-98;
         Posy = CAR.transform.position.y;
         Posz = CAR.transform.position.z;
 
         TIME = Time.time;
 
         SPEED = Car.velocity.magnitude;
 
         Time.fixedDeltaTime = 0.5f;
 
         WriteToFile(Posx, Posy, Posz, TIME, SPEED);     
     }    
     public static void WriteToFile(float Posx, float Posy, float Posz, float TIME, float SPEED)
     {
             string fileName = "_Traiettoria.txt";
             string textToAdd = (Posx + " " + Posy + " " + Posz + " " + TIME + " " + SPEED + "\r");            
 
             using (StreamWriter writer = new StreamWriter(Application.streamingAssetsPath + fileName, true))
 
             {
                 writer.Write(textToAdd);                               
 
                 writer.Close();
         }
       }    
 }
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
1
Best Answer

Answer by xxmariofer · Nov 17, 2020 at 01:28 PM

you are mixing concepts, simply leave the FixedUpdate for the physics, the fixedDeltaTime also controls how often physics get calculated, simply do something like this

      void Start()
      {      
  
          Posx = CAR.transform.position.x-98;
          Posy = CAR.transform.position.y;
          Posz = CAR.transform.position.z;     
          TIME = Time.time;  
          SPEED = Car.velocity.magnitude;
          StartCoroutine(UpdateCarRoutine());
      }  
 
      IEnumerator UpdateCarRoutine()   
      {   
          while(true)
          {
              Posx = CAR.transform.position.x-98;
              Posy = CAR.transform.position.y;
              Posz = CAR.transform.position.z;
  
              TIME = Time.time;
  
              SPEED = Car.velocity.magnitude;
  
              WriteToFile(Posx, Posy, Posz, TIME, SPEED);  
              yield return new WaitForSeconds(0.5f);//SET HERE YOUR DESIRED FREQUENCY
           } 
      }    

      public static void WriteToFile(float Posx, float Posy, float Posz, float TIME, float SPEED)
      {
              string fileName = "_Traiettoria.txt";
              string textToAdd = (Posx + " " + Posy + " " + Posz + " " + TIME + " " + SPEED + "\r");            
  
              using (StreamWriter writer = new StreamWriter(Application.streamingAssetsPath + fileName, true))
  
              {
                  writer.Write(textToAdd);                               
  
                  writer.Close();
          }
        }    




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 MarcoZan · Nov 17, 2020 at 02:04 PM 0
Share

thank you very much, the solution is perfect!

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

215 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 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 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 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 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 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 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 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 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 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

What is the difference between Update() , LateUpdate() , FixedUpdate(), and when i should use them 3 Answers

How to do Inputs in Update and AddForce in FixedUpdate, infinite jumps ? 0 Answers

Why does FixedUpdate work when Update() doesn't? 2 Answers

Raycast2D in update? 1 Answer

Choppy camera, moving player in FixedUpdate and enemies through navmesh 0 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