Enemies walking left and right

Dirk

Member
Hi, I don't want my monsters to pick their next direction randomly, but to let them walk to the left until they would hit a block and then let them walk right.
Does anybody of you know how to do this?
I wanted to modify the monster movement script, but my coding skills are not good enough yet.
I appreciate any help.
I have the feeling it shouldn't be too hard.
 

dale_coop

Moderator
Staff member
You need to modify (or make a new script, for example, "Movement_L.asm" based on) the "Routines/PlatformGame_Base/AiScrips/RandomMovement_2_LR.asm" script:
from
Code:
;;;; Choose out of 2 directions.
   ; JSR GetRandomDirection
;	AND #%00000110

	JSR GetRandomNumber
	AND #%00000001
	BEQ isEvenNumberFor2WayDirection
	;; is odd number for 2 way direction
	LDA #%00000010 ;; right
	JMP got2DirectionMovement
isEvenNumberFor2WayDirection:
	LDA #%00000110
got2DirectionMovement:
	
    TAY
    LDA DirectionMovementTable,y
    STA temp
    TYA ;; the 0-7 value for direction
    ORA temp
    STA Object_movement,x
to:
Code:
;;;; Go to the left direction.

    LDA #%00000110
	
    TAY
    LDA DirectionMovementTable,y
    STA temp
    TYA ;; the 0-7 value for direction
    ORA temp
    STA Object_movement,x
 

Dirk

Member
It's not working. The enemy starts walking left until it hits a block. It then tries to go right for 1 ms, but goes left again. So it makes a little look-right-look-left-look-right-look-left... dance.
 

Dirk

Member
Action Step 0:

  • Animation Type: Default
  • Action: 4 - Move LR Timer 0
  • EndAction: Repeat
  • End Animation: Loop
  • Animation Speed: 3

No Action Step Flags checked.

EDIT: Now, I solved it. I changed EndAction to Loop and now it works.

Thank you very much for your help dale_coop!
 

Dirk

Member
Me too :D
I even wrote a bit ASM code that checked if the current movement is left or right and changed it accordingly. And it worked! But then I found the simpler solution so I took my code out again. Still, I was a bit proud.
 

dale_coop

Moderator
Staff member
Great! We all started like that, small modification, then adding some lines, then making scripts ;)
 

torseelos

New member
I wrote your code in AI_ActionRoutines\AI_Action_11.asm.
Then named it "Move LR" in NESMaker -> Project Setting -> Action Types -> Action Type 11.
Now I can select Action 11 - Move LR and still have random as an option.

Thanks for the small victory =D
 
Top Bottom