- Home /
I have issuses with TimeDeltatime
I made a tilt for fps character (safer pick ups from the corners) and when moving with Q everything is fine. I mean the movement is slowing by Time.Deltatime, but when i am pressing the E button it fills that Time.Deltatime just dont work CODE: private void Tilt() {
if (Input.GetKey(KeyCode.Q))
{
playerController.transform.rotation *= Quaternion.Euler(0, 0, 20 * Time.deltaTime * 10);
Quaternion t = playerController.transform.rotation * Quaternion.Euler(0, 0, 20 * Time.deltaTime * 10);
if (t.eulerAngles.z > 20)
{
t = Quaternion.Euler(t.eulerAngles.x, t.eulerAngles.y, 20);
}
playerController.transform.rotation = t;
}
else if (Input.GetKey(KeyCode.E))
{
playerController.transform.rotation *= Quaternion.Euler(0, 0, -20 * Time.deltaTime);
Quaternion t = playerController.transform.rotation * Quaternion.Euler(0, 0, -20 *Time.deltaTime);
if (t.eulerAngles.z > 20)
{
t = Quaternion.Euler(t.eulerAngles.x, t.eulerAngles.y, -20);
}
playerController.transform.rotation = t;
}
else
{
playerController.transform.rotation *= Quaternion.Euler(0, 0, 0 * Time.deltaTime * 10);
Quaternion t = playerController.transform.rotation * Quaternion.Euler(0, 0, 0 * Time.deltaTime *
10); if (t.eulerAngles.z > 0) { t = Quaternion.Euler(t.eulerAngles.x, t.eulerAngles.y, 0); }
playerController.transform.rotation = t;
}
}
A good rule of thumb: do not read from eulers, only read ONCE and then store that vector to alter and write to them. They flip at -180 and 180 so it's going to give erroneous results. I can almost guarantee that is your problem here.
Answer by Bunny83 · Mar 07, 2020 at 02:59 AM
Uhm inside your "Q" code you multiply 200 (20 * 10) by deltaTime however inside your "E" code you only muliply 20 by deltaTime. Is that the difference you're seeing? If that's the case you really should pay more attention to your code.
Your answer
Follow this Question
Related Questions
Gradually scale platform? 4 Answers
Ideas for Animating while Paused? 9 Answers
Why are my bullets shooting at an unpredictable rate? 3 Answers
timer that can be reset 1 Answer