Game Development Community

OnKeyRelease(), or lack thereof in Torque

by ITT019_(0007) · in Artist Corner · 04/07/2006 (8:18 pm) · 6 replies

Here is my situation:

I am creating a game where the player character is an olive. (NO! STOP! KEEP READING!) This is what i want to happen:

1. Player presses and holds a key
2. Olive spins like dragster spinning slicks, "charging"
3. Player releases key
4. If key was held long enough, impulse vector is applied to olive, and olive shoots off like pinball.

Here is how i thought i would go about doing that:

1. Bind spin animation to key (duh)
2. Get time of keypress, pass it into a variable
3. Get time of key release, pass it into second variable
4. Compare difference in variables, if it meets or exceeds some threshhold value, then...
5. Impulse vector is applied

So, basically, the idea is that you have to hold the key down for 3 or 4 seconds to "charge" the olive, then when you release it it'll zoom off.

Try as i might, i can't find anything resembling an onKeyPress() or onKeyRelease() function in Torque. Don't tell me that Flash has it and Torque doesn't???

Any help would be greatly appreciated, as i am a po' Game Design student at ITT.

#1
04/08/2006 (1:42 am)
There is an onKeyRelease.

look at default.bind.cs at lines like:
moveMap.bind(keyboard, "up", moveforward);

that line maps the up arrow key to the function moveforward().
looking at moveforward() in the same file, we have:
function moveforward(%val)
{
// stuff
}

%val is 1 if the event is a keyPress, 0 if a keyRelease.


a good practise when developing w/ torque or any system
is to think of some existing part of the system which already does something similar to what you want,
and then go look at how it's done.
in this case, regular player moving forward seems pretty similar to the olive charging up.


the game sounds interesting! is the olive in a martini glass ?
#2
04/08/2006 (2:07 am)
What Orion says - use the %val

The pain is to get a keypress to repeat while holding down. There is only fired event at keypress/keyrelease, but not in between.

To solve that you would start a schedule() and stop it again on release that e.g. sends commandToServer or similar. But its only faking it.
#3
04/08/2006 (11:14 am)
Hey, thank you all for your time and insight. I think I have enough to start tinkering with now!

The olive is not in a martini glass -- it's trying to AVOID being skewered and plunked in a martini glass like his buddy was.
#4
04/09/2006 (11:31 pm)
Lol! nice.
#5
04/11/2006 (3:37 pm)
Someone with more expericne, is there a way to tell how many milliseconds have passed between an onKeyPress, and onKeyReleased event?

That may be one way he can do it.

function spacePressed(%val)
{
	if (%val == 1){
		// pressed
		$timeStarted =  ? ;  // what do we put here

	} else {
		// released
		%timeStopped = ? ;
		$forwardPower = (%timeStopped - $timeStarted) / 1000;
	}
}
#6
04/11/2006 (4:39 pm)
$Sim::Time is the simulation time in seconds.