Game Development Community

Can I get exact point in time when button was pressed by user?

by Adrian Gabriel · in Torque 3D Professional · 10/08/2014 (2:59 am) · 7 replies

Hey there,

I would like to use Torque3D for a scientific experiment togehter with an Oculus Rift.

I would like to create a 3D scene with Objects.The proband will have to push certain keys in the scene and react according to the action. The experiment will measure reaction time.

Therefore I need to know when a proband is pushing the "up-arrow" key for instance or how long it took him after he has seen an image to push another button. Is it possible to get that information via the scripting API? Furthermore is it possible, to track at which point in time an object started doing something in the scence?So I can get time intervales between actions in a scene?

Thank you very much!

Adrian

#1
10/08/2014 (8:15 am)
I think so - there are timer objects, and you could start a timer when your image is displayed, then keybind to stop the timer... in theory.

So, I believe the tools are there - I'll have to think about it for a minute to come up with a more concrete answer (that may or may not be more or less correct).
#2
10/08/2014 (2:02 pm)
Check out these functions. You'll probably want to use getRealTime, called once when your event happens and again when a button is pressed.
#3
10/09/2014 (12:28 am)
Hey Richard and Daniel,

thanks a lot for your replies! So I can keep track of the times of user actions and save the data in an external file to evaluate the data with Matlab for instance?
Do you happen to know what the latency is for a user pushing any button until the action "pushing button" is actually processed in Torque?This time interval would also be something important for the experiment to know.Or any idea where I could get that information?

Again thanks a lot!


Adrian
#4
10/09/2014 (8:06 am)
<shrug> you'd probably have to run a profiler to get the exact latency - should be pretty miniscule, though - the engine was originally meant for first-person shooters (twitch games) so control response is a priority....

You can dump whatever you like to file - just look at how the console.log file is generated and use that method. This one is trivial.
#5
10/09/2014 (8:16 am)
Don't forget it's also quite easy to hook up sqlite to T3D, if you get tired of parsing your text files! If you're going to to this kind of thing more than once you might consider it, there's a resource or two floating around to make it easy.
#6
10/09/2014 (12:57 pm)
Input events in Torque3D happen as soon as the input event message is processed by the event loop. Any delay in processing is therefor dependent on how slow your event loop is.

In Torque2D and earlier versions of tge/tgea, the input events were dispatched to a thread-safe event loop in which case the events might incur an additional delay due to copying and mutex locking.

#7
10/09/2014 (2:34 pm)
getRealTime isn't accurate enough. Try using startPrecisionTimer() and stopPrecisionTimer(). They return the number of milliseconds that's processed between the calls.

This still isn't 100% accurate because of what JamesU and ChrisC have said. But, more accurate than getRealTime at least

//.....
// display image
//.....

$timer_id = startPrecisionTimer();

// inside of your key function

$millisecondsPassed = stopPrecisionTimer($timer_id);

Since each timer takes a unique ID, you can have multiple run at a time too :)