- Home /
Storing Joystick movements, key depressed time
I have need to record both the length of time a key has been depressed for, and expanding beyond this to store joystick movements. What data type and method can I use to store joystick movements?
I am trying to apply an equal and opposite force automatically to an object by creating a method that will run upon user key or joystick input and apply the opposite of input after input ceases.
Answer by Proclyon · Nov 30, 2010 at 11:28 AM
Use the input manager built into Unity3D (Edit -> Project Settings -> Input) The keys defined here have a couple of variables that I think have exactly what you need. The reference to what they are you can see here
Btw nice title, I didn't know keys could be sad.
EDIT:
If you want to make your own code
Get 2 states stored
Pressed this frame Pressed previous frame
if !pressed previous frame and pressed this frame means key is held down while it's held down ( update routine) Increase a time value. And presto chango you have a measurement system in code for the time it has been measured Just don't forget to reset it if needed.
I can see how the code for keys will work with thanks.
I'm not so clear as to recording joystick movements, I realise I can GetAxis(Horizontal) etc every frame but here is what I am trying to achieve more specifically:
If the joystick is moved in a given axis away from zero value, or out of the deadzone value, I want to store those values so that when the input returns to less than the deadzone again, the values can be automatically applied back in a scripted method in the opposite direction. For example a small amount of thrust input from joystick will be applied after the axis is idle?
I think with the amount of coffee spillage my keys are hypertensive ;)