Having an issue with my FPS motion rig in blender. Not sure if it is my python script causing it or some issue with my logic bricks…
As you can see from the in game screenshot, I am having an issue where multiple actions are blending together. For example:
I can walk (W) then hold down Shift to run… the animation works fine. If I release the shift AND the W, then hit the W key again, the animation works fine.
BUT if I let go of the shift key, and still hold down the walk key (W) the actions sort of blend slightly. Then, if I iron-sight in while still holding the walk key, then iron sight out, I get the following in game screen. The actions are all blended together, and only fix themselves if I let all the keys go and it resets.
Here is my python:
from bge import logic as GameLogiccont = GameLogic.getCurrentController() own = cont.owner g1 = cont.sensors["g1"].positive g2 = cont.sensors["g2"].positive g3 = cont.sensors["g3"].positive g4 = cont.sensors["g4"].positive jump = cont.sensors["Space"] fwd = cont.sensors["W"] back = cont.sensors["S"] slft = cont.sensors["A"] srght = cont.sensors["D"] shift = cont.sensors["Shift"] lctrl = cont.sensors["Crouch"] iron_sight_s = cont.sensors["Iron_sight"] act = cont.actuators["floormove"] crouch_d = cont.actuators["Crouch_D"] crouch_u = cont.actuators["Crouch_U"] idle = cont.actuators["idle"] #gun anim ipo run = cont.actuators["run"] #gun anim ipo walk = cont.actuators["walk"] iron_sight_a = cont.actuators["iron_sight"] #head_bob = cont.actuators["Head_Bob"] ownc = crouch_d.owner if ownc["cstate"] == 1: #If crouching, slow down speed = 1 else: speed = 2 jspeed = 0 #unless we press the jump button our jump speed will be set to zero. sqrt2over2 = 0.70710678 if g1 or g2 or g3 or g4: #If any of the 4 ground sensors are within .54 BU from the ground, give user control over motion. #If you change this, user could jump high, start walking far above the ground if lctrl.positive and ownc["cstate"] == 0: #If we hit crouch (tap sensor), and we are not already crouching speed = 1 #slow down cont.activate(crouch_d) #Activate our crouch down animation ownc["cstate"] = 1 #Set our crouch state to crouched else: if lctrl.positive and ownc["cstate"] == 1: #If we hit crouch (tap sensor), and already crouched speed = 2 #speed up cont.activate(crouch_u) #activate our crouch up animation ownc["cstate"] = 0 #set our crouch state to NOT crouched if shift.positive:#If holding down the run button, speed up speed = 3 if ownc["cstate"] == 1: #If we are crouched and try to run, stand up and run cont.activate(crouch_u) #activate our crouch up animation ownc["cstate"] = 0 #stand up to start running if iron_sight_s.positive: print("IRON_SIGHT") speed = 1 cont.deactivate(run) cont.deactivate(idle) cont.deactivate(walk) cont.activate(iron_sight_a) fspeed = speed * (fwd.positive - back.positive) #fspeed, or forward speed, takes the walking/running/crouch speed and multiplies it by W key and S key pressure to equal our forward/backward speed sspeed = speed * (srght.positive - slft.positive) #sspeed or sidways speed, takes the walking/running/crouch speed and multiplies it by A key and D key pressure to equal our right/left speed if fspeed and sspeed: #if we are traveling sideways (Two keys held down) I believe attempting to slow the diagonal speed slightly. fspeed *= sqrt2over2 #variable set up as .707 in beginpning... unsure why that exact number? sspeed *= sqrt2over2 if own["rel"] == 0: #Disables forward and sideways speed (appears to be used for disabling walking when jumping) fspeed = 0 sspeed = 0 if not jump.positive: #If we aren't pressing the jump button, the property jstate on our player will be set to 1 own["jstate"] = 1 if jump.positive and own["jstate"] == 1: #If we are pressing the jump button, AND we aren't already jumping jspeed = 2 #set our jump speed own["jstate"] = 0 #set our jump state BACK to "not jumping" (disables double jump) own["rel"] = 0 #disable movement in the air cont.activate(idle) #disables the walk/run anim in the air act.linV = [-fspeed, sspeed, jspeed] #act = cont.actuators["floormove"] Taking speed (Side speed (D and A) print(fspeed) if [sspeed, fspeed, jspeed] == [0, 0, 0]: print("zeros") cont.deactivate(run) cont.deactivate(walk) cont.deactivate(act) cont.activate(idle) #cont.deactivate(head_bob) else: if ownc["cstate"] == 1 and (shift.positive + jspeed) == 0: cont.deactivate(idle) cont.activate(walk) #else: #cont.activate(idle) #cont.deactivate(run) if speed == 2 and fspeed != 0: # If walking forwards or backwards or DIAG cont.deactivate(run) cont.deactivate(idle) cont.activate(walk) #cont.deactivate(head_bob) print("walk_activated") else: #If walking sideways only if speed == 2: print("Sideways") cont.deactivate(walk) cont.activate(idle) if speed == 3: #If running #cont.activate(head_bob) cont.deactivate(walk) cont.deactivate(idle) cont.activate(run) print("run_activated") cont.activate(act) print("activating else") else: cont.deactivate(act) own["rel"] = 1