Checking the Player Objects State

drdocker

New member
I've created a falling state for my player and modified the physics script to enable the state when there are no collisions below the player. I only want to toggle this state if the player is currently in idle "0" or running "1". Any ideas on how I would construct the argument for this?
Code:
theGroundIsNotSolid2_b:
LDX player1_object
    ; change player to falling/ jumping state
	ChangeObjectState #$02, #$02
	JMP noCollisionHere_v
 

MistSonata

Moderator
The physics script is applied to all objects separately, loading the object ID into X one at a time and running the code from top to bottom. Loading a different value into X in the physics script is going to muck that up.

Instead, you want to check to see if the object being modified is the player object, so instead of loading the player ID into X, you'll want to compare X to the player ID and if they're equal run a code.

Here's an example of how you might do it with some code inserted after "DoneWithAllMovement", making sure it's the last thing that happens so that we don't have to worry if the current v speed is the final v speed.

Code:
DoneWithAllMovement:	

	CPX player1_object ;; this compares the current object loaded into X with the ID of the player object 
	BNE skipupdatestate ;; if you want this code to apply to ALL objects, not just the player, remove these two lines
	
	LDA Object_v_speed_hi,x
	BPL changetofalling ;; if your character's vertical speed is a positive non-zero number, it means the character is currently falling
		;;otherwise...
	BEQ changetolanded ;; if your character's vertical speed is zero it means you're not falling or jumping, so land
		;;otherwise...
	;;if the v-speed is not positive or equal to zero, then it must be negative (which means upward movement)
	ChangeObjectState #$01, #$00 ;; assuming your action step for jumping is 1
	JMP skipupdatestate
	
changetoland:
	;; if the v-speed is 0 that means the character has landed
	ChangeObjectState #$00, #$00 ;; assuming your action step for being on solid ground is 0
	JMP skipupdatestate
	
changetofalling:
	;; if the code gets to here, it means the player is falling, so change your state here
	ChangeObjectState #$02, #$00 ;;assuming your action step for falling is 2
		
skipupdatestate:

	LDY prevBank
	JSR bankswitchY
	
	RTS

That's how I'd do it, anyway.
 

drdocker

New member
Thanks so much @MistSonata !!! Got it working today with your help.

BulletBros_Nes.gif

@digitalbooty

Here is how I implemented MistSonata's suggestion. Not sure if this was the best place for it but seems to work fine. I added this in the GameEngineData\Routines\UserScripts\PlatformGame_Base\MainScripts\Physics_Platform_Simple.asm just before the doneWithVerticalMovement Label.

I ended up triggering the jump animation through the input manager and at the end of animation it goes to previous state which is falling. Combined with the vertical speed check for when walking off ledges without jump it works pretty well.

Code:
doneWithAllMovement:

	CPX player1_object ;; this compares the current object loaded into X with the ID of the player object 
	BNE skipupdatestate ;; if you want this code to apply to ALL objects, not just the player, remove these two lines
	
	LDA Object_v_speed_hi,x
	CMP #$01  ;; comparing it to 01 so it doesnt fall instantly. Looks better this way with animation
	BPL changetofalling ;; if your character's vertical speed greater than , it means the character is currently falling

	JMP skipupdatestate
	
	changetofalling:
	;; if the code gets to here, it means the player is falling, so change your state here
	ChangeObjectState #$02, #$00 ;;assuming your action step for falling is 2
	
skipupdatestate:

	LDY prevBank
	JSR bankswitchY
	
RTS

doneWithVerticalMovement:


RTS
 

MistSonata

Moderator
Very nice! I'm glad you were able to get it to work the way you like. :)

digitalbooty said:
That's awesome! Where would you put that script?

We're talking about the platform_physics_simple.asm included in NESmaker 4.0.11
 
Top Bottom