1
$\begingroup$

I have a player who i want to be able to throw spells and such, when you hold down the left mouse button, the spell charges, when you let go, the spell launches. I was able to do the animations with a work around, but that will not work with actually adding an object. How (with python) can i simply activate an actuator once when the mouse is released.

I don't need anything else (not mouse over, not if prop true) just plain-o'l plain-ol'. Thanks

$\endgroup$

2 Answers 2

1
$\begingroup$

here is how to detect a mouse button release and activate an actuator, using a Boolean property:

    mouse_Lclick = cont.sensors["Mouse_leftclick"] 

    if mouse_Lclick.positive :
        if not own['hold'] :
             # just pressed
             own['hold'] = True
        else :
             # button is held
    else :
        if own['hold'] :
            # button released
            own['hold'] = False
            cont.activate(actuator)  #activate the actuator
$\endgroup$
1
$\begingroup$
  1. You can detect button press by checking if the sensor is positive.
  2. You can detect button release by checking if the sensor is not positive.

As the sensor (with default settings) triggers on state change only, you can sense this situations with the primitive controllers.

enter image description here

  1. with AND, OR
  2. with NOR, NAND

Be aware this will not work when you connect more sensors to the same controller as they trigger regardless if the button is just pressed or just released.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.