4.5.9 A Fix For The Weapon Spawning Bug

Bucket Mouse

Active member
If you pull out your Melee Weapon in the Adventure module, then quickly change directions (as players tend to do when dodging enemy fire), the weapon will hang there in midair for the duration of the attack time, without you. This obviously looks bad. Joe mentions it in the tutorial videos and offers a theory on how to fix it, but stops short of telling you specifically how.

I don't know why anyone would want this in their game, so here is the fix.

Open doDrawSprites and toward the bottom, right after "doneDrawingThisSprite," throw this in:

Code:
        ;;;  THIS ADDED PART KEEPS THE MELEE WEAPON FROM STAYING ONSCREEN ONCE THE PLAYER SPRITE MOVES
        LDA Object_flags,x
        AND #%00000100
        BNE +isWeapon
        JMP +isNotWeapon
            +isWeapon
            LDA Object_type,x
        CMP #$01 ; attacking
        BEQ +isNotProjectile
        JMP +isNotWeapon
            +isNotProjectile
            TXA
            TAY
            GetActionStep player1_object
            CMP #$01 ; attacking
            BNE +isNotWeapon
            TYA
            TAX
            DestroyObject
        +isNotWeapon
                        ;;;; END OF ADDED PART

There, problem over.

Take note of where I've marked "Attacking." In my game I have it set to Action Step 02 (the third action). If you have your attack set to a different step, you should change the number to whatever yours is.
 
Last edited:

offparkway

Active member
If you pull out your Melee Weapon in the Adventure module, then quickly change directions (as players tend to do when dodging enemy fire), the weapon will hang there in midair for the duration of the attack time, without you. This obviously looks bad. Joe mentions it in the tutorial videos and offers a theory on how to fix it, but stops short of telling you specifically how.

I don't know why anyone would want this in their game, so here is the fix.

Open doDrawSprites and toward the bottom, right after "doneDrawingThisSprite," throw this in:

Code:
        ;;;  THIS ADDED PART KEEPS THE MELEE WEAPON FROM STAYING ONSCREEN ONCE THE PLAYER SPRITE MOVES
        LDA Object_flags,x
        AND #%00000100
        BNE +isWeapon
        JMP +isNotWeapon
            +isWeapon
            TXA
            TAY
            GetActionStep player1_object
            CMP #$02 ; attacking
            BEQ +isNotWeapon
            TYA
            TAX
            DestroyObject
        +isNotWeapon
                        ;;;; END OF ADDED PART

There, problem over.

Take note of where I've marked "Attacking." In my game I have it set to Action Step 02 (the third action). If you have your attack set to a different step, you should change the number to whatever yours is.
I'm super interested in this! As I've been having this same issue in the Brawler module, since the "punch" works like a melee weapon would.

I have two attacks: a punch and a kick. Using this code had no effect on my punch (when it seems like it should have, as it is action step 02) but my kick was affected instead (03) and the weapon object just disappears way too quickly, regardless if the player is moving or not. I changed the code to CMP 03, and that affected my punch but the same thing happens.... the weapon just flashes very briefly on screen and disappears.
 

Otterbits

New member
I'm super interested in this! As I've been having this same issue in the Brawler module, since the "punch" works like a melee weapon would.

I have two attacks: a punch and a kick. Using this code had no effect on my punch (when it seems like it should have, as it is action step 02) but my kick was affected instead (03) and the weapon object just disappears way too quickly, regardless if the player is moving or not. I changed the code to CMP 03, and that affected my punch but the same thing happens.... the weapon just flashes very briefly on screen and disappears.
This is what happened to me too, which is very frustrating. The weapon disappears so quickly I can barely even see it. Sometimes it doesn't even appear at all. Any idea how to fix this anybody?
 

offparkway

Active member
This is what happened to me too, which is very frustrating. The weapon disappears so quickly I can barely even see it. Sometimes it doesn't even appear at all. Any idea how to fix this anybody?
I ended up disabling inputs as long as my player was attacking. So he can't turn until the weapon (in my case a fist and a kick) goes away.
 

PasseGaming

Active member
I just watched the Brawler video and he also touches upon this but offers no fix. I don't understand how he couldn't see why no one would want this in their game. I would of addressed it straight away. Thanks for this!
 

Kanbei85

Member
If you pull out your Melee Weapon in the Adventure module, then quickly change directions (as players tend to do when dodging enemy fire), the weapon will hang there in midair for the duration of the attack time, without you. This obviously looks bad. Joe mentions it in the tutorial videos and offers a theory on how to fix it, but stops short of telling you specifically how.

I don't know why anyone would want this in their game, so here is the fix.

Open doDrawSprites and toward the bottom, right after "doneDrawingThisSprite," throw this in:

Code:
        ;;;  THIS ADDED PART KEEPS THE MELEE WEAPON FROM STAYING ONSCREEN ONCE THE PLAYER SPRITE MOVES
        LDA Object_flags,x
        AND #%00000100
        BNE +isWeapon
        JMP +isNotWeapon
            +isWeapon
            LDA Object_type,x
        CMP #$01 ; attacking
        BEQ +isNotProjectile
        JMP +isNotWeapon
            +isNotProjectile
            TXA
            TAY
            GetActionStep player1_object
            CMP #$01 ; attacking
            BNE +isNotWeapon
            TYA
            TAX
            DestroyObject
        +isNotWeapon
                        ;;;; END OF ADDED PART

There, problem over.

Take note of where I've marked "Attacking." In my game I have it set to Action Step 02 (the third action). If you have your attack set to a different step, you should change the number to whatever yours is.

I applied this code at the bottom of doDrawSprites, and I have gotten no change in the behavior we want to fix. The sword still sits there, and you can still walk away from it. I used CMP #$02 because attack is action step 02 for me. I can't tell this code made any improvement, or in fact any change at all.
 

dale_coop

Moderator
Staff member
in your Move input script, add a piece of code to check if your player is in his attack state, of he is, stop the script...
Placing something like, at the begining of those scripts:
Code:
    STX temp
    GetActionStep temp
   
    CMP #$01    ;; or maybe #$02 (if your attack state is action step 2)
    BNE +notAttacking
        ;; stop the script
        RTS
    +notAttacking:
   
    ;; the rest of the script
 

Kanbei85

Member
in your Move input script, add a piece of code to check if your player is in his attack state, of he is, stop the script...
Placing something like, at the begining of those scripts:
Code:
    STX temp
    GetActionStep temp
  
    CMP #$01    ;; or maybe #$02 (if your attack state is action step 2)
    BNE +notAttacking
        ;; stop the script
        RTS
    +notAttacking:
  
    ;; the rest of the script


Yes, I added that script, and it did not fix the floating sword problem. The sword seems to be outlasting the attack state, or something like that.
 

dale_coop

Moderator
Staff member
Make sure you set your sword object's action step 0 to "destoyMe" after a timer value. (like ti was explained in the intermediate tutorial videos)

Personally, I use a timer value of "1" and set my End Timer to "DestroyMe".
 

Kanbei85

Member
Make sure you set your sword object's action step 0 to "destoyMe" after a timer value. (like ti was explained in the intermediate tutorial videos)

Personally, I use a timer value of "1" and set my End Timer to "DestroyMe".
Yes, that's how mine is set. The animation is on Loop, but the Timer is on 1 and the End Action is DestroyMe. The problem here was discussed in the tutorial, but not resolved.
 

dale_coop

Moderator
Staff member
If you add the ode I shared earlier...
"If the player is in his attacking state... don't execute that moving script"
In all your Move input scripts, it should prevent your player to actually moving.
In that script I used the action step 1 (check my comment in the script), you might have to adapt it to YOUR needs.
Also try to synchronize your attack action step to the time your weapon is on screen (same timer value)

What is your Player's action step used for attack?
(I don't know which one it is, it depends of the module... What module are you using?)
 

Kanbei85

Member
If you add the ode I shared earlier...
"If the player is in his attacking state... don't execute that moving script"
In all your Move input scripts, it should prevent your player to actually moving.
In that script I used the action step 1 (check my comment in the script), you might have to adapt it to YOUR needs.
Also try to synchronize your attack action step to the time your weapon is on screen (same timer value)

What is your Player's action step used for attack?
(I don't know which one it is, it depends of the module... What module are you using?)

Yes, I did add this code. My action step is 02 for attack, and I did update the code for that. It did not fix the weapon spawning problem. As I said, I can only guess that somehow the sprite for the weapon is lasting longer than the action state of attacking, for some reason.

This problem also exists when you are being recoiled from taking damage. If your sword is extended and you get hurt by a monster, you will recoil AWAY from your sword, which will just sit there hanging in space.
 

dale_coop

Moderator
Staff member
you need to synchronize the Player's action step 2 and the Weapon's action step 0... yourself.

I mean by that, use the same settings for the timer.
if you set the weapon action step 0 to Timer value "1" with a End Timer to "DestroyMe", you need to set your player's action step 2 to End Timer "GotoFirst" with a timer value of "1" (like your weapon).

Oh, you mean the parenting... like "attaching" the weapon to the player's positions/facing... if the player moves, you want the weapon to follow it.
You will need to add a few lines of code for that. Not sure if anyone has shared that for the 4.5.X anywhere yet. (I remember there was a guide for the 4.1... but it will not work with the current version of NESmaker).
 

Kanbei85

Member
The problem is not really fixed all the way (and you can still recoil away from the sword), but I did find it got better by switching the sword extension to a 2 frame animation at the highest speed, and then destroying the sword after animation, rather than using a timer. The quickest timer setting (1) is just too slow.
 
Top Bottom