[4.5] Move left, right, up or down AI monster scripts

JFranco

New member
Hey gang,

If you're looking for AI Monster scripts to move your monster left, right, up or down -- here's a solution that worked for me:

MoveLeft.asm
Code:
	TXA	
	STA tempA
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC

MoveRight.asm
Code:
	TXA													
	STA tempA											
	LDA #%00000011 ;; "right"									
	TAY													
	LDA DirectionTable,y										
	STA tempB											
	LDA FacingTable,y										
	STA tempC											
	StartMoving tempA, tempB, #$00							
	ChangeFacingDirection tempA, tempC


MoveUp.asm
Code:
	TXA	
	STA tempA
	LDA #%00000001  ;; goes up
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC

MoveDown.asm
Code:
	TXA	
	STA tempA
	LDA #%00000000  ;; "down"
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC


Cheers,
Justin
 

TolerantX

Active member
Thank you JFranco for these scripts! They are extremely helpful! I had trouble with the move left script and fixed it:

Code:
	TXA	
	STA tempA
	LDA #$02
	TAY
	LDA DirectionTable,y
	STA tempB
	LDA FacingTable,y
	STA tempC
	StartMoving tempA, tempB, #$00
	ChangeFacingDirection tempA, tempC
 

Lother

Member
Great ! But how to make it work in the ArcadePlatformer module ? Because when I check "Ignore gravity" for the go up or go down the monster stays in place.
 

mouse spirit

Well-known member
I believe this is for adventure, meaning no gravity is involved. It may be a more involved process in the physics to make stuff "fly" how you want in your game. But it also could be an option already,im not sure as i have not watched all the vids yet..
 

AllDarnDavey

Active member
Lother said:
Great ! But how to make it work in the ArcadePlatformer module ? Because when I check "Ignore gravity" for the go up or go down the monster stays in place.

Looks like it should work, make sure you set a max speed and acceleration speed in the monster object details. That's usually my mistake, it should be moving, and I find out I have my max speed set to zero.
 

twin paradox

New member
Thank you for these but I wanted to piggy-back on Lother's comment that the Up/Down movement scripts do not seem to work in the Platform module. I have the Ignore Gravity flag set and I have given the monsters speed and acceleration and they still won't move up and down. I am going to dig around in the ladder tile code to see if that can maybe be applied in some way.
 

PasseGaming

Active member
I don't think they work in the scrolling shooter module either. Though I can't be sure as the monster is actually never on screen when I arrive. So I'm assuming it's either because it works and they moved off screen or it's doing something funky and not appearing. I've seen monsters not appear on screen before depending on the action steps I gave it so I cant be sure either way. It's frustrating as I need my boss monster to move up and down while shooting at the player and I can't seem to pull it off.
 
Lother said:
These two settings are set, but my monster can only move left and right.

This appears to make it work if you edit doHandlePhysics_ArcadePlatformBase.asm, paste code over doneWithGravity bit.
Code:
doneWithGravity:

VerticalMovement:
	LDA Object_direction,x
	AND #%00100000
	BEQ +noVertMovement
		;; there is vertical movement
		LDA Object_direction,x
		AND #%00010000
		BEQ +isUpMovement
			;; is down movement
			LDA Object_y_lo,x
			CLC
			ADC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			ADC myMaxSpeed+1;Object_v_speed_hi,x
			STA yHold_hi
				CLC
				ADC self_bottom
				CMP #BOUNDS_BOTTOM ;#240
			
				BCS doBottomBounds
					JMP +noVertMovement
				doBottomBounds:
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$00
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
		+isUpMovement
			LDA Object_y_lo,x
			SEC
			SBC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			SBC myMaxSpeed+1;Object_v_speed_hi,x
			BCC +doTopBounds ;; helps if top bounds is zero. 
			STA yHold_hi
			CMP #BOUNDS_TOP
				BEQ +doTopBounds
				BCC +doTopBounds
					JMP +noVertMovement
				+doTopBounds
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$02
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
	+noVertMovement
skipPhysics:
 

Lother

Member
UltraNarwhal said:
Lother said:
These two settings are set, but my monster can only move left and right.

This appears to make it work if you edit doHandlePhysics_ArcadePlatformBase.asm, paste code over doneWithGravity bit.
Code:
doneWithGravity:

VerticalMovement:
	LDA Object_direction,x
	AND #%00100000
	BEQ +noVertMovement
		;; there is vertical movement
		LDA Object_direction,x
		AND #%00010000
		BEQ +isUpMovement
			;; is down movement
			LDA Object_y_lo,x
			CLC
			ADC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			ADC myMaxSpeed+1;Object_v_speed_hi,x
			STA yHold_hi
				CLC
				ADC self_bottom
				CMP #BOUNDS_BOTTOM ;#240
			
				BCS doBottomBounds
					JMP +noVertMovement
				doBottomBounds:
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$00
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
		+isUpMovement
			LDA Object_y_lo,x
			SEC
			SBC myMaxSpeed;Object_v_speed_lo,x
			STA yHold_lo
			LDA Object_y_hi,x
			SBC myMaxSpeed+1;Object_v_speed_hi,x
			BCC +doTopBounds ;; helps if top bounds is zero. 
			STA yHold_hi
			CMP #BOUNDS_TOP
				BEQ +doTopBounds
				BCC +doTopBounds
					JMP +noVertMovement
				+doTopBounds
					CPX player1_object
					BEQ +isPlayer
						DestroyObject
						JMP skipPhysics
					+isPlayer
						
						LDA yPrev
						STA yHold_hi
						STA Object_y_hi,x
						; LDA #$00
						; STA Object_v_speed_hi,x
						; STA Object_v_speed_lo,x
						; LDA #$02
						; STA screenUpdateByte
						; JSR doHandleBounds
						JMP skipPhysics
	+noVertMovement
skipPhysics:

Ok that works perfectly, thanks.
 

Yan

Member
Does anyone know a way to adapt UltraNarwhal's fix to work with "doHandlePhysics_PlatformBase.asm" instead of "doHandlePhysics_ArcadePlatformBase.asm"? I've been having some trouble making it work with a game that has scrolling.
 

Craigery

Active member
Does anyone know a way to adapt UltraNarwhal's fix to work with "doHandlePhysics_PlatformBase.asm" instead of "doHandlePhysics_ArcadePlatformBase.asm"? I've been having some trouble making it work with a game that has scrolling.
Paste the code in doHandlePhysics_PlatformBase, just below Line 444.
doneWithH:
you can remove
VerticalMovement:
So right after what we pasted should the Object_vulnerability check. I tried moving a monster up and down and it seems to work for me.
 
  • Like
Reactions: Yan

Bucket Mouse

Active member
I'm curious why you have it written to destroy an object that uses Up or Down if it's not the player?

Code:
                CPX player1_object
                    BEQ +isPlayer
                        DestroyObject
                        JMP skipPhysics

I had to comment those lines out to get it to work with my monster. Otherwise it would just disappear the instant the screen loaded.
 

5kids2feed

Well-known member
EDIT: NEVERMIND. Answered myself! It was the stop moving/movement coding. Carry on.

Question!

I can move my player up, down, left, and right now (with @UltraNarwhal's code) which is great.. BUT... i have the ignore gravity flag on as soon and as i move and let go, gravity kicks in.. i press up.. i'll move up until i let go and then i'll drop.. i press left.. i'll move left and drop as soon as i let go.... it has something to do with the "VerticalMovement:" part.. because when i remove that.. i'll go left and right and not drop at all after.. but i just cant go up and down anymore if i remove that.. so it doesn't help. How would I fix it so it won't drop? Basically "Ignore Gravity" flag no longer works when we enter this code. Is it this code or is it something with my stop movement/moving code afterwards which is just the stock coding? Thanks in advance!
 
Last edited:

vanderblade

Active member
Paste the code in doHandlePhysics_PlatformBase, just below Line 444.

you can remove

So right after what we pasted should the Object_vulnerability check. I tried moving a monster up and down and it seems to work for me.
I tried using this method with the PlatformBase physics script and it didn't have any effect. My up and down movement scripts still just produce a left or right movement.

Update: I did a little more testing. Oddly, If I don't move my player at all when starting the game, the default projectile now does go up (even though I don't want it to or have it set to the MoveUp script). But as soon as I move, all projectiles, even the one with the AI to move an object up, just go left or right. So this is progress, but there's something that needs adjusting.

Anybody else have luck here? Any ideas, @Craigery?
 
Last edited:

tbizzle

Well-known member
I tried to use the code for right movement. I pasted it into AI_Behavior4. It works great on the monsters, but it is now making my Player Object do the moonwalk!!! Any way to fix this or anything I could try to adjust? Also it seems to have taken away my Player Objects walking animations.

 

latetera

Member
I tried to use the code for right movement. I pasted it into AI_Behavior4. It works great on the monsters, but it is now making my Player Object do the moonwalk!!! Any way to fix this or anything I could try to adjust? Also it seems to have taken away my Player Objects walking animations.


In your "player" edit window go to "object details" -> actions (tab) -> and set animation speed = 1 or more
 

tbizzle

Well-known member
I tried using this method with the PlatformBase physics script and it didn't have any effect. My up and down movement scripts still just produce a left or right movement.

Update: I did a little more testing. Oddly, If I don't move my player at all when starting the game, the default projectile now does go up (even though I don't want it to or have it set to the MoveUp script). But as soon as I move, all projectiles, even the one with the AI to move an object up, just go left or right. So this is progress, but there's something that needs adjusting.

Anybody else have luck here? Any ideas, @Craigery?
To get it to work with the PlatformBase code I had to add it at the very end of the script below "doneWithGravity:"
 
Top Bottom