A More Platformer Friendly Recoil

WolfMerrik

New member
I am starting to recode/code my own Physics
It basically replaces the "DetermineRecoilDirection:" Inside of the HandleObjectCollisions.asm script with one better suited for a platformer.

In Constants.asm I changed the values to:
Code:
HURT_TIMER = #$0A
INVINCIBILITY_TIMER = #$16
RECOIL_SPEED_HI = #$03	;The value used for the upward knock
RECOIL_SPEED_LO = #$02	; The value used for the horizontal knock

New constants could easily be made and used in place to get a better HI/LO, but this works just fine for me.
I liked it, so I thought I would share it, I will put the code for the script in the next post,

or

If you want, you can download the file HERE, which has instructions in the header how to use/install it!
 

WolfMerrik

New member
Code:
; This script should be added to / Replace the current "DetermineRecoilDirection"
;
; In a platformer engine, we do not need to do 4-way recoils (well... we do, just not the same way!)
; In this way, all the recoils (except downward) give an upward vertical boost and a horizontal
; We use the values in Constants.asm, the hi = upward_recoil_amount, and the lo = horizontal_recoil_amount
; Feel Free to change this how you wish!
;
; Script by -WolfMerrik
DetermineRecoilDirection:
	LDA recoil_selfX	; First check for the abs x value
	SEC			; This is the same as the originals
	SBC recoil_otherX	; In the first few lines, as I dont fully understand it
	BCS absCheckDone	; as of yet. but it is what we use to determine direction of the colision
	EOR #$FF		; If we wanted... we could just use our facing direction for the 
	CLC			; Horizontal... which is what a LOT of older platformers did
	ADC #$01		; It opens up things to "damage boosting", which can be a lot of fun =P
absCheckDone:			; That will likely be my next recoil script.
	STA temp
	LDA recoil_selfY
	SEC
	SBC recoil_otherY
	BCS absCheckDone2	
	EOR #$FF			
	CLC
	ADC #$01
absCheckDone2:
	CMP temp
	BCS wasVertical
	JMP wasNotVertical
wasVertical:
	; Nothing yet!
	LDA recoil_selfY
	CMP recoil_otherY
	BCS recoilDown 		; branch to recoilDown, basically "recoilUp" is below
	LDA Object_v_speed_hi	; We use this consant for the "knock up", this case, Knock "down"
	SEC
	SBC #RECOIL_SPEED_HI
	STA Object_v_speed_hi,x
	LDA Object_v_speed_lo	; We use this consant for the "knock up", this case, Knock "down"
	SEC
	SBC #RECOIL_SPEED_HI
	STA Object_v_speed_lo,x
	JMP endVertical		; Skip down, avoiding the next two
recoilDown:
	LDA #$01		; Small amount, but it just works more naturually.
	STA Object_v_speed_hi,x	; Since this is our only "Knock Down"
	STA Object_v_speed_lo,x	
	JMP endVertical		; Get out to avoid the wasNotVertical
wasNotVertical:	
	LDA #$00		; No vertical, so no "special"
	SEC			; Height values
	SBC #RECOIL_SPEED_HI	; We use this consant for the "knock up"
	STA Object_v_speed_hi,x	; This could be changed to be lower, if greater than the value
	STA Object_v_speed_lo,x	; OR Add to the value (Subtract) To be used like a damage boost
endVertical:
	LDA recoil_selfX
	CMP recoil_otherX
	BCS recoilRight			; branch to recoilRight, basically "RecoilLeft" is below	
	LDA #$00
	SEC
	SBC	#RECOIL_SPEED_LO	; Remember, LO is used for H-Recoil
	STA Object_h_speed_lo,x
	STA Object_h_speed_hi,x
	JMP endRecoil			; Avoid the right recoil as well
recoilRight:
	LDA	#RECOIL_SPEED_LO	; Remember, LO is used for H-Recoil
	STA Object_h_speed_lo,x
	STA Object_h_speed_hi,x
endRecoil:	
	LDA #%10000000
	STA temp1
	LDA Object_movement,x
	AND #%00000111
	ORA temp1
	STA Object_movement,x	
	RTS
 

dale_coop

Moderator
Staff member
Good idea WolfMerrik, I was thinking the recoil was a little too strong, too (for a plate former) :p
 

WolfMerrik

New member
dale_coop said:
Good idea WolfMerrik, I was thinking the recoil was a little too strong, too (for a plate former) :p

Thanks, man, I thought so too,
Adjusting the settings worked, but not enough for my liking
 

WolfMerrik

New member
It really doesn't need to set the _lo values as it does, And I did this more out of a bad habit,
You could easily remove those lines and add
Code:
	LDA #$00		; Load a 0 value to set.
	STA Object_v_speed_lo,x	; Set the lo_values
	STA Object_h_speed_lo,x	; for both in one go.

At the start of endRecoil:

I am also not entirely sure if the:

Code:
	LDA #%10000000
	STA temp1
	LDA Object_movement,x
	AND #%00000111
	ORA temp1
	STA Object_movement,x

Is needed at the end... It WAS used in the old one, but doesn't seem to affect much on removal.
If anyone knows why it is good or bad, let me know!
 

Gazimaluke

Member
WolfMerrik said:
Wow, that I cannot explain haha

I took the scriptfiles from the zipped file and reset them. But it still has the same error. I have no idea what I have done. But replacing all the scripts with unmodified once should have fixed it. But no. So I really can't do much with the game right now. I will try to retrace my steps today and see if I might have done some other modification along the way. But all asm files are in the Routines folder aren't they? I will try to figure out if I did any changes in any other asm files thinking I was in the right file. But that should have been fixed when I replaced them with the unmodified files.
 

Gazimaluke

Member
WolfMerrik said:
Wow, that I cannot explain haha

I took the scriptfiles from the zipped file and reset them. But it still has the same error. I have no idea what I have done. But replacing all the scripts with unmodified once should have fixed it. But no. So I really can't do much with the game right now. I will try to retrace my steps today and see if I might have done some other modification along the way. But all asm files are in the Routines folder aren't they? I will try to figure out if I did any changes in any other asm files thinking I was in the right file. But that should have been fixed when I replaced them with the unmodified files.
 

WolfMerrik

New member
Gazimaluke said:
I re-imported the platform module and now the game is compiling again and I will give this another try.

I wish you the best. I have definitely made edits to the wrong file and it took me a VERY long time to retrace my steps.
 

Gazimaluke

Member
WolfMerrik said:
I wish you the best. I have definitely made edits to the wrong file and it took me a VERY long time to retrace my steps.

It's working now. I must have. Edited the wrong file or done something else wrong.
I want an animation when getting hit. How do I set hurt animation?
 

WolfMerrik

New member
Gazimaluke said:
It's working now. I must have. Edited the wrong file or done something else wrong.
I want an animation when getting hit. How do I set hurt animation?

Im glad that you did!
That would be an AWFUL thing; to lose that progress.

To change the player hurt animation_state, go to Platform_HandlePlayerHurt.asm

Near the top, you will see this line
Code:
	ChangeObjectState #$00, #$00 ; Change me to your hurt state!

Easy peasy! But sometimes finding WHERE to look is the hard part haha
 

Dirk

Member
A very nice script, thank you!
I have a little problem though. I set:
Code:
ChangeObjectState #$03, #$00 ; Change me to your hurt state!
My player plays the hurt animation, but when I jump afterwards it shows the idle animation. If I wait a short while after he got hurt he'll display the jumping animation as usual, but for a short time frame, maybe a second, he'll jump with his standing animation.

I just decreased the emulation speed and I noticed the player will show the first one or two frames of the jumping animation, but then changes to the idle/standing animation.

Do you have an idea why this keeps happening?

Thank you for your script again! It handles and looks much better/cuter now even with that little quirk I'm experiencing.
 

WillElm

New member
I implemented this and it worked for the player, but now my monsters only recoil to the left. I see the JSR for DetermineRecoilDirection in HandleMonsterHurt.asm. I find it weird that in the default code, the monsters recoil AWAY from the player, where in this modified code, they only go to the left, even though in both codes, both player and monster are running the same thing.

*EDIT* actually, my player only recoils to the left also with this code. What I really want is for the monster to ALWAYS recoil to the left or right. In my game, sometimes it seems like the game detect a hit on the bottom or something which leads to no monster recoil, which often leads to damage to the player since you're expecting recoil.

There must be something in the default code that loads the face direction of the object? And in the modified code, it's relative to the player only perhaps?
 
Top Bottom