Delay between Time.time and InputSystem.InputAction.CallbackContext.startTime
Hello ! I'm working on a Movement system using Unity's new Input System, I thought I understood everything but apparently no : I was trying to get the time since the player pressed Shift to use it into a Arctan function or something to have an acceleration over time, so I've read the doc and saw that startTime was returning the time code when we pressed the Key, the only thing I had to do was to get Time.time - startTime
to get what I wanted. but it appeared that startTime always gave me a time code ~5 seconds bigger than Time.time. I'm trying to understand why, and how to get the right time code. Hoping that I well explained my problem, this is my first time asking for something here.
Answer by WiTekh · Dec 02, 2020 at 11:20 AM
Okay so since I don't want to stay blocked on that problem for too long, I've temporarly fixed this by creating my own "startTime" variable : float m_startTime = 0.0f; float bool m_isRunning; float bool m_prevRunning;
void Awake()
{
m_playerInput = new PlayerInput();
m_playerInput.Land.Run.performed += p_ctx =>
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
m_isRunning = p_ctx.ReadValue<float>() == 1;
};
}
void Update()
{
if (m_isRunning && !m_prevRunning)
m_startTime = Time.time;
m_prevRunning = m_isRunning;
}
Don't forget to notify me when you have a better option or a more optimised code ^^