Game Development Community

Alternate Fire/Holding down mouse button

by Matt Huston · in Torque Game Engine · 04/16/2006 (6:50 am) · 5 replies

For a weapon I have, I need the player to hold down the left mouse button for it to charge. (I think there were weapons like this in Unreal Tournament) So, if the player just clicks left mouse button, weapon should do one thing, if they hold it, it does another. Any ideas on how to go about this?

Thanks!

#1
04/16/2006 (8:37 am)
Will somthing like this work:

moveMap.bindCmd(mouse,"button 0","chargeWeapon();","fireWeapon();");

The chargeWeapon function is called when the mouse button is pressed, and the fireWeapon function is called when the button is released. At least I think that will work, it works with keys, so I don't know why it wouldn't work with the mouse.
#2
04/16/2006 (8:39 am)
O rly

This revelation to me will come in handy when "charging" how far a grenade throw will be. :)
#3
04/16/2006 (8:45 am)
Yes, getting there, I am thinking like this...

Case A: Fire weapon normally
Case B: Fire weapon charged

All of those with left mouse button, so not every attack is going to be a charged attack.

I would use the Right Mouse Button, however that is already used for another item and it is more intuitive for my purpose to keep the Fire modes with the same button.
#4
04/16/2006 (8:54 am)
@Matt, Tom Perry got you part of the way there. The rest of it would be to save the time the button was pressed in chargeWeapon and the time it was released in fireWeapon. Then calculate the difference between the two. If it is less than a certain amount of time (<250ms?) then it would be a normal fire. If it was held beyond that, then calculate how much longer and set the charge level based on that.
#5
04/16/2006 (9:11 am)
Tom Ogburn - Yep thats what I was thinking after I posted.