Help with Nate's janky object parenting w/ melee weapon 4.1.5

mouse spirit

Well-known member
Heres a link to the original post.Scroll down past dale_coop's wonderful tutorial.
http://www.nesmakers.com/viewtopic.php?f=35&t=1777&hilit=janky

For the most part it works fine.Except if i hit left then turn to the right.
As you may be able to see, the sword sprite does not match the correct direction.
If someone could help me fix this it would be much appreciated.

jankyness.gif
Code:
;; Nate's janky object parenting w/ melee weapon/ w/ edits from dale_coop
;;;;;;;;;;;for new jump attack and other stuff

     LDX player1_object
   
    LDA Object_animation_frame,x
    STA temp
    
    LDA Object_movement,x
    AND #%00000111
    STA temp3
    TAY
    
    LDA Object_x_hi,x
    SEC 
    SBC #$10 ;; width of melee weapon 
    CLC
    ADC weaponOffsetTableX,y
    STA temp1
    
    LDA Object_y_hi,x    
    CLC
    ADC weaponOffsetTableY,y
    SEC
    SBC #$08 ;; height of melee weapon
    STA temp2
    
    LDX player1_weapon
	LDA Object_type,x
	CMP #OBJECT_PLAYER_MELEE
	BNE +
    LDA temp1
    STA Object_x_hi,x
    LDA temp2
    STA Object_y_hi,x
    
    LDA Object_movement,x
    ORA temp3
    STA Object_movement,x

		+
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
I was noticing something very similar, if I spammed my attack button really fast when facing to the right, I could also get this to happen.
 

mouse spirit

Well-known member
This is an old topic, but one of the last things that I need to fix for my first game. If anyone can help . I need the sword to follow the player more closely when jumping, and I need the sword to act correctly when hitting left,then turning to the right
 

SciNEStist

Well-known member
Sorry if this doesn't apply, but perhaps you could do something with the input scripts,

when hitting the right button, you would check if the attack button is being held down. if so, then end the attack and start a new attack.

since your attack isnt an animation, this might appear seamless.


Of course if you can't get a solution to this, an alternative would be to disable switching directions when attacking.
 

mouse spirit

Well-known member
Sorry if this doesn't apply, but perhaps you could do something with the input scripts,

when hitting the right button, you would check if the attack button is being held down. if so, then end the attack and start a new attack.

since your attack isnt an animation, this might appear seamless.


Of course if you can't get a solution to this, an alternative would be to disable switching directions when attacking.
After messing with my specific problem for a long time. It appears to be how nesmaker handles things.
You certainly have good ideas. It would be best for me to write different code for it truly.
I do want it to not happen though. Maybe i will make it so you cant turn while hitting.....sadly.
Thank you.
 

Knietfeld

Member
LDA Object_movement,x
ORA temp3
STA Object_movement,x
Since it looks like your only issue is with the weapon's facing direction, I think your problem is on these last three lines.
The way nesmaker's object facing direction works, #%00000010 is facing right and #%00000110 is facing left. When you ORA the two numbers, no matter which one is first you always get the same result, #%00000110, which makes it face left. When your weapon was created facing right and you turn to face left it does just that, 010 ORA 110 = 110. But if your weapon was created facing left and you turn the player to the right the way the code is now it just gets the player1_object's new direction (010) and ORA's it with the weapon's left facing direction (110), so it's 010 ORA 110 = 110 still facing left. To fix it is pretty simple once you know what the problem is. Just insert a line to always reset the weapon's facing direction before combining the player's direction with it. So,

LDA Object_movement,x
AND #%11111000
ORA temp3
STA Object_movement,x

And I think that'll fix it. Now you also mentioned the weapon not following the player closely when jumping? I couldn't see any problem in your gif above. Is it just a frame behind all the time? If so, that might have to do with when this code is being executed. I had an issue like that in my game and it was happening because I think my code was in pre_sprite instead of post_sprite, so the weapon was being placed next to the player but then the sprite placement code would move the player before everything would draw.

If that's not your issue you could explain it more and I would help you diagnose the problem. Your game looks great, I'd hate for a little issue like that to keep you from reaching your vision for it.

Good luck, I hope I helped!
 
Last edited:

mouse spirit

Well-known member
Since it looks like your only issue is with the weapon's facing direction, I think your problem is on these last three lines.
The way nesmaker's object facing direction works, #%00000010 is facing right and #%00000110 is facing left. When you ORA the two numbers, no matter which one is first you always get the same result, #%00000110, which makes it face left. When your weapon was created facing right and you turn to face left it does just that, 010 ORA 110 = 110. But if your weapon was created facing left and you turn the player to the right the way the code is now it just gets the player1_object's new direction (010) and ORA's it with the weapon's left facing direction (110), so it's 010 ORA 110 = 110 still facing left. To fix it is pretty simple once you know what the problem is. Just insert a line to always reset the weapon's facing direction before combining the player's direction with it. So,

LDA Object_movement,x
AND #%11111000
ORA temp3
STA Object_movement,x

And I think that'll fix it. Now you also mentioned the weapon not following the player closely when jumping? I couldn't see any problem in your gif above. Is it just a frame behind all the time? If so, that might have to do with when this code is being executed. I had an issue like that in my game and it was happening because I think my code was in pre_sprite instead of post_sprite, so the weapon was being placed next to the player but then the sprite placement code would move the player before everything would draw.

If that's not your issue you could explain it more and I would help you diagnose the problem. Your game looks great, I'd hate for a little issue like that to keep you from reaching your vision for it.

Good luck, I hope I helped!
Thank you so much. I will try it out tonight.
 

mouse spirit

Well-known member
Since it looks like your only issue is with the weapon's facing direction, I think your problem is on these last three lines.
The way nesmaker's object facing direction works, #%00000010 is facing right and #%00000110 is facing left. When you ORA the two numbers, no matter which one is first you always get the same result, #%00000110, which makes it face left. When your weapon was created facing right and you turn to face left it does just that, 010 ORA 110 = 110. But if your weapon was created facing left and you turn the player to the right the way the code is now it just gets the player1_object's new direction (010) and ORA's it with the weapon's left facing direction (110), so it's 010 ORA 110 = 110 still facing left. To fix it is pretty simple once you know what the problem is. Just insert a line to always reset the weapon's facing direction before combining the player's direction with it. So,

LDA Object_movement,x
AND #%11111000
ORA temp3
STA Object_movement,x

And I think that'll fix it. Now you also mentioned the weapon not following the player closely when jumping? I couldn't see any problem in your gif above. Is it just a frame behind all the time? If so, that might have to do with when this code is being executed. I had an issue like that in my game and it was happening because I think my code was in pre_sprite instead of post_sprite, so the weapon was being placed next to the player but then the sprite placement code would move the player before everything would draw.

If that's not your issue you could explain it more and I would help you diagnose the problem. Your game looks great, I'd hate for a little issue like that to keep you from reaching your vision for it.

Good luck, I hope I helped!
I see now. Yeah when i tried to mess with it,i thought my issue had to do with temp3,
i just didnt know how to fix it right.Thank you so much,it works great!

Also thanks for you nice words about the game.And you have fixxed one of the last things that needs fixxed
for it not to seem janky.

For the other issue,its only when i jump, or moreso on the way down. My sword cant keep up.
I do have it in predraw. I will try in postdraw.
Or actually, a terminal velocity would be great too.Either way.
 

Knietfeld

Member
Funny story. I've been working on an old project in version 4.1.5 to try to pull something together to share for byte-off 2021 (as of right now I'm on plan C for what I think I can get done in time) and last night when I was testing stuff, I realized that my old game needs exactly this "janky parenting" code I helped you with to make it's melee weapon work better. I guess I solved that issue a totally different way in my more recent project and never figured it out back then in 4.1.5. So you helped me out here too! I don't have to start from scratch solving the issue. Funny how that worked.
 
Heres a link to the original post.Scroll down past dale_coop's wonderful tutorial.

For the most part it works fine.Except if i hit left then turn to the right.
As you may be able to see, the sword sprite does not match the correct direction.
If someone could help me fix this it would be much appreciated.

View attachment 3344
Code:
;; Nate's janky object parenting w/ melee weapon/ w/ edits from dale_coop
;;;;;;;;;;;for new jump attack and other stuff

     LDX player1_object
  
    LDA Object_animation_frame,x
    STA temp
   
    LDA Object_movement,x
    AND #%00000111
    STA temp3
    TAY
   
    LDA Object_x_hi,x
    SEC
    SBC #$10 ;; width of melee weapon
    CLC
    ADC weaponOffsetTableX,y
    STA temp1
   
    LDA Object_y_hi,x   
    CLC
    ADC weaponOffsetTableY,y
    SEC
    SBC #$08 ;; height of melee weapon
    STA temp2
   
    LDX player1_weapon
    LDA Object_type,x
    CMP #OBJECT_PLAYER_MELEE
    BNE +
    LDA temp1
    STA Object_x_hi,x
    LDA temp2
    STA Object_y_hi,x
   
    LDA Object_movement,x
    ORA temp3
    STA Object_movement,x

        +
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Incredible. How did you get the character to crouch down? What about background tile animations? I was making a game in 4.1, but I ended up dropping it because I didn't understand how to do these things... Now I'm studying the latest version...
 
Heres a link to the original post.Scroll down past dale_coop's wonderful tutorial.

For the most part it works fine.Except if i hit left then turn to the right.
As you may be able to see, the sword sprite does not match the correct direction.
If someone could help me fix this it would be much appreciated.

View attachment 3344
Code:
;; Nate's janky object parenting w/ melee weapon/ w/ edits from dale_coop
;;;;;;;;;;;for new jump attack and other stuff

     LDX player1_object
  
    LDA Object_animation_frame,x
    STA temp
   
    LDA Object_movement,x
    AND #%00000111
    STA temp3
    TAY
   
    LDA Object_x_hi,x
    SEC
    SBC #$10 ;; width of melee weapon
    CLC
    ADC weaponOffsetTableX,y
    STA temp1
   
    LDA Object_y_hi,x   
    CLC
    ADC weaponOffsetTableY,y
    SEC
    SBC #$08 ;; height of melee weapon
    STA temp2
   
    LDX player1_weapon
    LDA Object_type,x
    CMP #OBJECT_PLAYER_MELEE
    BNE +
    LDA temp1
    STA Object_x_hi,x
    LDA temp2
    STA Object_y_hi,x
   
    LDA Object_movement,x
    ORA temp3
    STA Object_movement,x

        +
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
It is possible to add animation of the stopped character? very good project, guy..
 
Top Bottom