SOLVED [4.5.6] Stop Momentum

Craigery

Active member
I am trying to have my player snap to a tile when you press down and change action step, but if you are moving left/right when you snap you will continue to move even after snapping and the action step change. Here is my tile code:


Code:
;;playerShadowVarCheck
	LDA playerShadow		;;Variable is named playerShadow
	CMP #$00				;;compares against 0
	BEQ gamepadShadowCheck	;;If it is 0, go to gamepadShadowCheck
	JMP endShadowTileAttempt	;;If it is NOT 0, then go to end.
	
	GetActionStep player1_object
	CMP #$04
	BEQ +endShadowTileAttempt
	
gamepadShadowCheck:	
	LDA gamepad			;;Loads gamepad
	AND #%0100000 		;;checks if Down is pressed
	BNE startShadowTileAttempt	;;if so then go to startShadowTileAttempt
	JMP endShadowTileAttempt	;;jump to endShadowTileAttempt

startShadowTileAttempt:
;	PlaySound #sfx_Shadow

	LDA tileX
	AND #%11110000
	STA Object_x_hi,x
	STA xHold_hi
	
	LDA tileY
	AND #%11110000
	SBC #$01
	STA Object_y_lo,y
	STA yHold_hi
	
	LDA #$00
	STA Object_v_speed_lo,x
    LDA #$00
	STA Object_v_speed_hi,x

	LDA #$01
	STA playerShadow

	ChangeActionStep player1_object, #$04

endShadowTileAttempt:

I have this near the end, I was hoping that would cancel out the momentum, but that doesn't appear so. Does anyone have any experience with this or have any ideas?

Code:
	LDA #$00
	STA Object_v_speed_lo,x
	LDA #$00
	STA Object_v_speed_hi,x
 

mouse spirit

Well-known member
Momentum has to do with acceleration i think. Like it seems to deal with "slipspeed" also.
Meaning the rate at which you stop, not just start.
But i am no expert.
 

Ayrik

New member
You can see in oStopMoving.asm a section to stop all inertia. I haven't tried it, but hopefully this helps.
Code:
LDA Object_direction,x
AND #%01011111
STA Object_direction,x
 

Craigery

Active member
Ayrik said:
You can see in oStopMoving.asm a section to stop all inertia. I haven't tried it, but hopefully this helps.
Code:
LDA Object_direction,x
AND #%01011111
STA Object_direction,x

I tried this with no luck.



I took at look at StopMoving.asm and found there is a StopMoving MACRO, but its not stopping.

Code:
StopMoving arg0, arg1
	;arg0 = object
	;arg1 = stop inertia in what direction, FF = all

Here is how I added it, its near the bottom

Code:
;;playerShadowVarCheck
	LDA playerShadow		;;Variable is named playerShadow
	CMP #$00				;;compares against 0
	BEQ gamepadShadowCheck	;;If it is 0, go to gamepadShadowCheck
	JMP endShadowTileAttempt	;;If it is NOT 0, then go to end.
	
	GetActionStep player1_object
	CMP #$04
	BEQ +endShadowTileAttempt
	
gamepadShadowCheck:	
	LDA gamepad			;;Loads gamepad
	AND #%0100000 		;;checks if Down is pressed
	BNE startShadowTileAttempt	;;if so then go to startShadowTileAttempt
	JMP endShadowTileAttempt	;;jump to endShadowTileAttempt

startShadowTileAttempt:
;	PlaySound #sfx_Shadow

	LDA tileX
	AND #%11110000
	STA Object_x_hi,x
	STA xHold_hi
	
	LDA tileY
	AND #%11110000
	SBC #$01
	STA Object_y_lo,y
	STA yHold_hi
	

StopMoving player1_object, #$FF
	;arg0 = object
	;arg1 = stop inertia in what direction, FF = all
	
	LDA #$01
	STA playerShadow

	ChangeActionStep player1_object, #$04

endShadowTileAttempt:
 

mouse spirit

Well-known member
Can you say #$00 for object instead? Also, i believe you would have to be colliding with the
tile constantly for any of the code to work. I would suggest messing with an input script rather than just the tile script.
As checking for a variable based on tile collision in an input seems like the way to achieve this.
 

dale_coop

Moderator
Staff member
Your error could just be the first part of the script:
Code:
;;playerShadowVarCheck
	LDA playerShadow		;;Variable is named playerShadow
	CMP #$00				;;compares against 0
	BEQ gamepadShadowCheck	;;If it is 0, go to gamepadShadowCheck
	JMP endShadowTileAttempt	;;If it is NOT 0, then go to end.

This looks not correct for me...
What is playerShadow? Is it your player object? The object doing the action?
For testing, you should comment out those lines (to see if it's the cause of your issue)
 

Craigery

Active member
dale_coop said:
Your error could just be the first part of the script:
Code:
;;playerShadowVarCheck
	LDA playerShadow		;;Variable is named playerShadow
	CMP #$00				;;compares against 0
	BEQ gamepadShadowCheck	;;If it is 0, go to gamepadShadowCheck
	JMP endShadowTileAttempt	;;If it is NOT 0, then go to end.

This looks not correct for me...
What is playerShadow? Is it your player object? The object doing the action?
For testing, you should comment out those lines (to see if it's the cause of your issue)

The intention of the playerShadow variable for the player is to help prevent snapping to multiple tiles of the same type. If I have 4 of these Shadow tiles next to each other when you activate one it will keep snapping to the next one. With the variable it will snap to one, change the variable, then not be able to snap to the next one until the variable resets when you Release Down.

Removing that section did change the momentum going LEFT, but not going RIGHT. I did remove the next bit that was being skipped over about comparing to action state 04.
 

Craigery

Active member
mouse spirit said:
Can you say #$00 for object instead? Also, i believe you would have to be colliding with the
tile constantly for any of the code to work. I would suggest messing with an input script rather than just the tile script.
As checking for a variable based on tile collision in an input seems like the way to achieve this.

Not sure how to combine the tile code with input code in this scenario. If I could figure out how to compare the player1_object against a tile that would be great, but I don't know of a way to get a tile type so I could CMP against it. Does anyone know how to get the tile type you are colliding with?

I moved the line StopMoving player1_object, #$FF to be before the snapping code and if I move LEFT it will cancel out the momentum, but not if I am moving RIGHT. Continuing to investigate for future generations.

Current tile code:

Code:
	LDA gamepad			;;Loads gamepad
	AND #%0100000 		;;checks if Down is pressed
	BNE startShadowTileAttempt	;;if so then go to startShadowTileAttempt
	JMP endShadowTileAttempt	;;jump to endShadowTileAttempt

startShadowTileAttempt:
;	PlaySound #sfx_Shadow

	StopMoving player1_object, #$FF
	;arg0 = object
	;arg1 = stop inertia in what direction, FF = all
	
	LDA tileX
	AND #%11110000
	STA Object_x_hi,x
	STA xHold_hi
	
	LDA tileY
	AND #%11110000
	SBC #$01
	STA Object_y_lo,y
	STA yHold_hi
	
	LDA #$01
	STA playerShadow

	ChangeActionStep player1_object, #$04
	
endShadowTileAttempt:
 

Craigery

Active member
Sorry for the triple post; I changed the Action Step action to be StopMoving (why didn't I think of that earlier?(because I need more sleep)). Thanks for the help! Hopefully my example will help someone else.
 
Top Bottom