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();
}
}
}