Disable sensor check

A few questions here actually:

I have an iron sight animation that mostly works using this code:

if 	iron_sight_s.positive and own["iron_sight"] == 0: 		print("IRON_SIGHT")
		speed = 1
		cont.deactivate(run)
		cont.activate(iron_sight_a)
		own["iron_sight"] = 1
		
		
	if not iron_sight_s.positive and own["iron_sight"] == 1:
		speed = 2
		print("iron_end")
		cont.activate(iron_sight_a)
		own["iron_sight"] = 0

However, a few problems. I don’t want iron sight to be a toggle, I want you to have to hold down the key to iron sight, although I do have the action as a “ping pong” in my logic block, but I was hoping the python code could play the action back to beginning when I release the key.

Also, I was hoping to disable iron_sight entirely when I am running, by either disabling the sensor (which doesn’t seem possible?) or somehow disabling the actuator for the duration of the run. Is the only way to do that by setting up states in my logic editor (which I THINK will work)? Or can I do that in python?

My blend can be downloaded from here:
https://docs.google.com/open?id=0Bz170qNApm2Aa21kRDlFU3VYdzA

It may be somewhat tricky to get it working with a ping pong action actuator. Since ping pong plays the action continuously, I think you’d have to activate it and then deactivate it when it has reached the desired frame. A more easy solution would be to either just use the playAction method or have two normal action actuators, one that plays the action forward and one that plays it backward.

As for disabling the use of iron sights when running, you should have a state property that keeps track of what state the player is in (e.g. running, idle, walking, etc.). Just add the extra logic to your first if statement “and own[‘state’] != ‘run’”.

The first thing I tried was 2 normal action actuators, one forward one back, but if I just click the right mouse (iron_sight) momentarily (not long enough for the full animation) it gets “stuck” midway between both actions and won’t go to one or the other, and not sure how to solve that issue… the playaction method would have the same issue I would assume. Do you know what might be causing that and how to fix it?

I did the state variable and that works fine, once I get the iron_sight issue figured out I will need to force it out of iron sight to start running, but at least it is a start.

The ping pong animation works okay for the most part, click the mouse button once and it completes the entire animation, but stays sighted in and the variable for “not sighted” get triggered, so script thinks it is not sighted in… not nice… also makes the animation a “toggle” animation, which I don’t want.

Solved using a combination of

getActionFrame(1) and
playAction

directly, like so:


if iron_sight_s.positive and own["iron_sight"] == 0 and run_state == 0: #if we are pressing right mouse, and not sighted in, and not running    own["iron_sight"] = 1    # set our state to sighted in
    speed = 1 #decrease our speed
    currFrame = ownarms.getActionFrame(1) #get the current frame of the animation (we might be middle of animation from going OUT of iron sight, need to reverse the animation to go back into iron sight
    ownarms.playAction("FPS.Arms.SGun.IronS", currFrame, 10, 1, 0, 5, bge.logic.KX_ACTION_MODE_PLAY, 0, 1) #Directly playing the animation from the current frame to frame 10 (sighted in)
        
if not iron_sight_s.positive and own["iron_sight"] == 1 and run_state == 0: #if we are pressing right mouse, and sighted in, and not running
    own["iron_sight"] = 0 # set our state to sighted out
    speed = 2 #increase our speed
    currFrame = ownarms.getActionFrame(1) #get the current frame of the animation (we might be middle of animation from going into iron sight, need to reverse the animation to go back out of iron sight
    ownarms.playAction("FPS.Arms.SGun.IronS", currFrame, 1, 1, 0, 5, bge.logic.KX_ACTION_MODE_PLAY, 0, 1) #Directly playing the animation from the current frame to frame 1 (sighted out)