Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34

Thread: Double Tap to Run/Sprint

  1. #21
    Member Cotaks's Avatar
    Join Date
    May 2012
    Location
    The Netherlands
    Posts
    1,108
    Originally Posted by MarcoYolo View Post
    So this came up...
    indentation error means you are missing a tab or space.
    your script does not have the proper structure


    it should look like this:
    Code:
    from bge import logic, events
    
    
    owner = logic.getCurrentController().owner
    scene = bge.logic.getCurrentScene()
    armature = owner.scene.objects['PlayerRig']
    
    
    
    
    move = 0
    delay = 10
    cool = 10
    
    
    key_none = logic.KX_INPUT_NONE
    key_tap = logic.KX_INPUT_JUST_ACTIVATED
    key_active = logic.KX_INPUT_ACTIVE
    
    
    UPARROWKEY = logic.keyboard.events[events.UPARROWKEY]
    
    
    ## Tap Counter ##
    if UPARROWKEY == key_tap:
        owner["TAP"] += 1
    	if owner["TAP"] >= 2:
    	    owner["TAP"] = 2
    	    owner["TIMER"] = 0
    	    owner["RUN"] = True
    
    
    ## Double Tap Timer ##
    if owner["TAP"] == 1:
        owner["TIMER"] += 1
    	if owner["TIMER"] > delay:
    	    owner["TIMER"] = 0
    	    owner["TAP"] = 0
    
    
    ## Move ##
    if UPARROWKEY == key_active:
        armature.playAction("PlayerWalking", 1, 9)
        move = -0.06
        
    	if owner["RUN"] == True:
    	    move = -0.2   
    ## Reset Walk Cool Down ##
    elif UPARROWKEY == key_none and owner["TAP"] == 2:
        owner["TIMER"] -= 1
    
    
    	if owner["TIMER"] < -cool:
    	    owner["TAP"] = 0
    	    owner["TIMER"] = 0
    	    owner["RUN"] = False
    
    
    owner.applyMovement((0,move,0), True)
    Last edited by Cotaks; 14-Sep-17 at 20:37.
    '- It's not working' then check your console like: this
    Did you know that you can make a complete game with the .blends that i share?



  2. #22
    Member
    Join Date
    Oct 2014
    Location
    Long Beach, Ca
    Posts
    114
    Wait, I might be missing something. Am I suppose to connect an action actuator?



  3. #23
    armature = scene.objects['PlayerRig']

    deleted the "owner."
    System "IVAN" (rev 1.3b) - Win7 64bit - Blender 2.74:
    CPU- Intel i3-3220 3.30 Ghz | GPU- EVGA GTX 970 | RAM- GSkill Ares 16GB 1600 Mhz | MB- ASUS P8Z77-V LK



  4. #24
    Member Cotaks's Avatar
    Join Date
    May 2012
    Location
    The Netherlands
    Posts
    1,108
    Originally Posted by MarcoYolo View Post
    Wait, I might be missing something. Am I suppose to connect an action actuator?
    No, playAction() will replace that brick

    just look at my sig, first line, and report the errors here.
    or simply make a demo file and upload it, so we can check it.
    Last edited by Cotaks; 15-Sep-17 at 08:59.
    '- It's not working' then check your console like: this
    Did you know that you can make a complete game with the .blends that i share?



  5. #25
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    2,021
    @MarcoYolo: it is completely normal to need help with things..but I really suggest you start with some simpler scripts...if you are not able to figure this one out, you need to go learn some scripting basics...it is not difficult...anyone can code, not everyone can code well(I'M REFFERING TO ME )...oops damn caps

    You may also want to stick with just bricks at first...I have been using bge now going on 4 months?...I'm really not sure how long.... and I am still figuring things out.
    "The crows seem to be calling my name." Thought Kaw.
    Myrlea, "The Shepherd's Quest" formerly "Valiant" [project]



  6. #26
    Member
    Join Date
    Oct 2014
    Location
    Long Beach, Ca
    Posts
    114
    Here's a sample file, it's basically a cube parented to an armature.

    DoubleTap.blend

    All elements should be the same. Note that the armature contains script.



  7. #27
    Member Cotaks's Avatar
    Join Date
    May 2012
    Location
    The Netherlands
    Posts
    1,108
    Originally Posted by MarcoYolo View Post
    Here's a sample file, it's basically a cube parented to an armature.

    DoubleTap.blend

    All elements should be the same. Note that the armature contains script.
    Ok as expected some spaces in fron of tabs can mess up the script, just replaced every line for you.
    after that next error comes up, bge not defined. that is due to you import logic from bge, so using bge.logic wont work.

    removed the scene line, as i said you dont need to grab the scene, i know he told you to get rid of it, but still you dont need it so removed it.

    also i said armature.playAction you used own.playAction fixed that as well (own in this case is not bad, but you dont want the script hanging on the armature)

    fixed blend:
    DoubleTap (1).blend

    #edit
    normally you parent your mesh to armature, then you create a bounding box, then parent the armature to the bounding box, and on the bounding box you place all the scripts. and all physics (collision bounds, dynamic type, etc) and you set the mesh + armature on no collision.
    Last edited by Cotaks; 15-Sep-17 at 14:46.
    '- It's not working' then check your console like: this
    Did you know that you can make a complete game with the .blends that i share?



  8. #28
    Member
    Join Date
    Oct 2014
    Location
    Long Beach, Ca
    Posts
    114
    Originally Posted by Cotaks View Post
    Ok as expected some spaces in fron of tabs can mess up the script, just replaced every line for you.
    after that next error comes up, bge not defined. that is due to you import logic from bge, so using bge.logic wont work.

    removed the scene line, as i said you dont need to grab the scene, i know he told you to get rid of it, but still you dont need it so removed it.

    also i said armature.playAction you used own.playAction fixed that as well (own in this case is not bad, but you dont want the script hanging on the armature)

    fixed blend:
    DoubleTap (1).blend

    #edit
    normally you parent your mesh to armature, then you create a bounding box, then parent the armature to the bounding box, and on the bounding box you place all the scripts. and all physics (collision bounds, dynamic type, etc) and you set the mesh + armature on no collision.
    Well thanks! I couldn't figure out what was happening. I also didn't realize I was supposed to use armature.playAction() instead of own.playAction()

    I forgot to remove the scene line. I also tried fixing the tabs and spaced but to no avail.

    I also don't know where bge.logic came from

    Well thanks for helping me out. It means a lot...



  9. #29
    Member Cotaks's Avatar
    Join Date
    May 2012
    Location
    The Netherlands
    Posts
    1,108
    I also don't know where bge.logic came from

    Well thanks for helping me out. It means a lot...
    Np, you had it in the scene line.
    '- It's not working' then check your console like: this
    Did you know that you can make a complete game with the .blends that i share?



  10. #30
    Member
    Join Date
    Oct 2014
    Location
    Long Beach, Ca
    Posts
    114
    Oh, I didn't see that. This makes me realize how sensitive scripts can be...



  11. #31
    Member Cotaks's Avatar
    Join Date
    May 2012
    Location
    The Netherlands
    Posts
    1,108
    Originally Posted by MarcoYolo View Post
    Oh, I didn't see that. This makes me realize how sensitive scripts can be...
    has nothing to do with sensitive.

    you do:
    from bge import logic

    so using bge.logic wont work, you need to call logic on its own.

    python is indeed indent sensitive, just look at it this way, a function, an if statement and while/for loops are basically containers. If you want them to use some sort of code you need to indent it, so a single tab wil place the code into that container.

    good:
    Code:
    if 'a' != 'b':
        print(inside the if statement)
    wrong:
    Code:
    if 'a' != 'b':
    print(outside the if statement)
    and in your case 'move = -2' was outside the statement
    Last edited by Cotaks; 15-Sep-17 at 17:19.
    '- It's not working' then check your console like: this
    Did you know that you can make a complete game with the .blends that i share?



  12. #32
    Member
    Join Date
    Oct 2014
    Location
    Long Beach, Ca
    Posts
    114
    So I have a quick problem. So everytime I start to run, it doesn't stop running.



  13. #33
    featuring idle, walk, and run animations
    Attached Files Attached Files
    System "IVAN" (rev 1.3b) - Win7 64bit - Blender 2.74:
    CPU- Intel i3-3220 3.30 Ghz | GPU- EVGA GTX 970 | RAM- GSkill Ares 16GB 1600 Mhz | MB- ASUS P8Z77-V LK



  14. #34
    Member
    Join Date
    Oct 2014
    Location
    Long Beach, Ca
    Posts
    114
    Thanks! That definitely fixed my problem. I seriously couldn't have done it without you guys!



Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •