[4.5.6] Removing recoil code and allowing player to move during hurt invincibility

Jonny

Well-known member
(metro-vania scrolling module)

Has anyone sucessfully removed the recoil script completely and allowed the player to move during hurt invincibility?

Basically, I've stopped the recoil from happening but I also want to be able to carry on moving the player in hurt state. i.e the only hurt effect is that 1 health is removed and the player turns invincible for a couple of seconds.
 

dale_coop

Moderator
Staff member
if your hurt effect (invisible for a couple of seconds) is a player animation (action step 7), you can't move. If you could move , the player would no more in action step 7, he would be moving (action step 1)... so, now way to visualize he's hurt, also, means no cooldown timer (the hurt animation works as a cooldown moment), so your player will lose ALL his health (because still colliding with the monster during a few frames).
Or maybe... you should allow the movements but keeping the hurt animation (action step).

Check the moveUp/moveLeft/moveRight/moveDown scripts... they checking of the player is in his hurt animation, if he is, the code is skipped. You will need to modify that behavior.

For example, currently the moveRight.asm looks like that:
Code:
    TXA
    STA temp ;; assumes the object we want to move is in x.
  GetActionStep temp
    CMP #$07
    BNE +notHurt
        RTS
    +notHurt
    
        StartMoving temp, #RIGHT
        TXA
        STA temp ;; assumes the object we want to move is in x.
        ChangeFacingDirection temp, #FACE_RIGHT
        
    RTS

Try commenting our the lines checking the action step... like that:
Code:
    TXA
    STA temp ;; assumes the object we want to move is in x.
  ; GetActionStep temp
    ; CMP #$07
    ; BNE +notHurt
    ;     RTS
   ;  +notHurt
    
        StartMoving temp, #RIGHT
        TXA
        STA temp ;; assumes the object we want to move is in x.
        ChangeFacingDirection temp, #FACE_RIGHT
        
    RTS
 

Jonny

Well-known member
I tried that exact thing and it made no difference, by thank you anyway.

Tbh I thought that would work too, but because player is still in action step 7, something else is preventing movement.
Maybe the physics are not observed if in hurt.

I thought maybe someone had tried it already. I know a lot more games where the player simply goes invincible for a few seconds and can carry on moving than ones where the player is recoiled backwards and cant move.

I'll keep trying...
 

Yan

Member
I also wanted my playable character to become invincible for a few seconds after being hurt so I added a "invincibilityTimer" variable.

Example of how it would work in a "Handle Player Hurt" script:
Code:
;Add this at the start unless it interferes with something else you might have added
LDA invincibilityTimer
BEQ +actuallyHurt
JMP +skipHurt
+actuallyHurt

;Add this after the +notDeadYet
LDA #$40 (change the number as you see fit)
STA invincibilityTimer

Plus this in "Handle Game Timer" script:
Code:
LDA invincibilityTimer
BEQ +skip
DEC invincibilityTimer
+skip

I hope I'm not missing anything, if you want to make the player flicker on and off while invincible then I posted about it here:
 

Jonny

Well-known member
Cheers Yan.

This is a lot better than the way I was attempting it (with an action step 7 animation).

I do have a question about it... with this code would I still be putting my player into action 7 hurt state or is it inteded to be running while still in running or idle state?
 

Jonny

Well-known member
You can have it both ways, just comment out or remove the action step 7 and recoil stuff from your player hurt script if you don't want that.

Thanks again. I'm sure I can figure it out in time now with the code help.
 

Ekenz

New member
I also wanted my playable character to become invincible for a few seconds after being hurt so I added a "invincibilityTimer" variable.

Example of how it would work in a "Handle Player Hurt" script:
Code:
;Add this at the start unless it interferes with something else you might have added
LDA invincibilityTimer
BEQ +actuallyHurt
JMP +skipHurt
+actuallyHurt

;Add this after the +notDeadYet
LDA #$40 (change the number as you see fit)
STA invincibilityTimer

Plus this in "Handle Game Timer" script:
Code:
LDA invincibilityTimer
BEQ +skip
DEC invincibilityTimer
+skip

I hope I'm not missing anything, if you want to make the player flicker on and off while invincible then I posted about it here:
On the line "LDA #$40 (change the number as you see fit)" what does that number correlate to?
 

Peter Schmitz

Active member
On the line "LDA #$40 (change the number as you see fit)" what does that number correlate to?
That is the duration of the invincibility - the timer starts at 40 and decreases and when the variable invincibilityTimer reaches 0 - your player can be hurt again
 

Jonny

Well-known member
Can you show what is on the lines in the scripts you're getting the errors for? Line 2 / Line 45
 

SHLIM

Active member
is there a way to limit how far the player recoils? by default it keeps going until it hits a solid object, but it would be good if it just recoiled for a short distance
 

dale_coop

Moderator
Staff member
is there a way to limit how far the player recoils? by default it keeps going until it hits a solid object, but it would be good if it just recoiled for a short distance
Yes, just reduce the "speed" of the recoil.
In your Physics script, change the value of RECOIL_SPEED_HI and RECOIL_SPEED_LO.
 

baardbi

Well-known member
is there a way to limit how far the player recoils? by default it keeps going until it hits a solid object, but it would be good if it just recoiled for a short distance
It's important to set a timer on action step 7 (hurt state). If you set the action timer to 1 and "End of Action" to "Go to First" you will reduce the recoil time.
 
Top Bottom