[4.5.9] Dynamic Moving Platforms that carry the player any direction

SciNEStist

Well-known member
This tutorial will be able to help you create objects that your player can walk on and be carried by both vertically and horizontally. It is written for Metroidvania, but should work with other platformers. One huge feature is that it is capable of working across multiple screens in a scrolling game, something you don't see in many official NES games! As with any new change to your game, Backing up your files is highly recommended first!

There is a lot you can do with this other than just elevators. For example, this is a simplified version of the platform used in the Game Land Ahoy! to create the pirate ship that you ride. In that game, I added controls to the ship and tiles to push the platform up and down. You could also do something like adding monsters that turn into platforms when they die so you can jump across a large gap. The possibilities are endless!

Step 1: Load the new files
Copy the files provided doHandleObjectCollisions_PlatformerBasePlatforms.asm, doCompareBoundingBoxes_multiScreenplatform, and doHandleUpdateObjectsplatform.asm to your games\Subroutines folder

Step 2: Add the Action step Label
open up Project Settings and under "project labels" tab, click monster action step flags on the left. On the Right, change Flag1 to "Walkable"

Step 3: Add the object Variable
while still in Project settings, under the "Object Variables" tab, add attachedTo as a variable.

Step 4: Set the new files
While still in your project settings, under "Script Settings" tab:
  • Change "Handle Object Collisions" to doHandleObjectCollisions_PlatformerBasePlatforms.asm. If you have previously modded this script, then you can also open the script and see where the changes are clearly marked to modify your own.
  • Change the "Compare Object Boxes" to doCompareBoundingBoxes_multiScreenPlatforms.asm
  • Change the "Handle Object Updates" to doHandleUpdateObjectsPlatform.asm
Step 5: Add the ability to jump off a platform
on the Left go to Scripts >Input Scripts > and find the script "jump_throughPlat.asm" and add the following lines after line 11
Code:
LDA attachedTo
BEQ +
    JMP +doJump
+

Now we can move on to creating your object!

Step 1: Create your object, set its bounding box, acceleration, max speed, and any other behaviours.
Step 2: In any action steps that you want the player to be able to walk on top of/be carried by this object, Make sure the "Walkable" action step flag is checked.

DONE!

But Wait, "How do I make a object that moves up and down?" you ask! Well, here's one method:

Step 1: open up the Handle Physics script, look around line 444, you will see this code:
Code:
  doneWithH:
    LDA Object_vulnerability,x
    AND #%00000001
    BEQ +skip
        ;;; What should we do if vulnerability bit 0 is flipped?
        JMP doneWithGravity
    +skip

replace it with this:

Code:
  doneWithH:
    LDA Object_vulnerability,x
    AND #%00000001
    BEQ +skip
        LDA Object_vulnerability, x
        AND #%00000010
        BEQ +notplatform
            LDA Object_y_lo,x
            ADC Object_v_speed_lo,x
            STA yHold_lo
            LDA Object_y_hi,x
            ADC Object_v_speed_hi,x
            STA Object_y_hi,x
            STA yHold_hi
        +notplatform
        JMP doneWithGravity
    +skip

Step 2: take the following 3 code snippets and save them to different .asm files in your "Game\AI_Scripts\" Folder. then set them as AI behaviours in the script settings. You should also label them under "Project Labels" tab accordingly.

platformstopvert.asm
Code:
    ;STOP
    LDA #$00
    STA Object_v_speed_lo,x
    STA Object_v_speed_hi,x

platformdown.asm
Code:
    ;DOWN
    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    STA Object_v_speed_hi,x

platformup.asm
Code:
    ;UP
    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x

Step 3: set your platform object's Jump Speed to be the speed you want the platform to move up and down at. Most people would want to set it the same as the max movement speed.

Step 4: in the action steps, set the new AI behaviours in the object details window under the Actions Tab with the Action drop Down menu. Make sure that both "Walkable" and "Ignore Gravity" are both checked!


Follow these instructions, and you can have something like this:

 

Attachments

  • Platform.zip
    4.9 KB · Views: 7
Last edited:

smilehero65

Active member
This tutorial will be able to help you create objects that your player can walk on and be carried by both vertically and horizontally. It is written for Metroidvania, but should work with other platformers. As with any new change to your game, Backing up your files is highly recommended first!

There is a lot you can do with this other than just elevators. For example, this is a simplified version of the platform used in the Game Land Ahoy! to create the pirate ship that you ride. In that game, I added controls to the ship and tiles to push the platform up and down. You could also do something like adding monsters that turn into platforms when they die so you can jump across a large gap. The possibilities are endless!

Step 1: Load the new files
Copy the files provided doCompareBoundingBoxes_multiScreenplatform and doHandleUpdateObjectsplatform.asm to your games\Subroutines folder

Step 2: Add the Action step Label
open up Project Settings and under "project labels" tab, click monster action step flags on the left. On the Right, change Flag1 to "Walkable"

Step 3: Add the object Variable
while still in Project settings, under the "Object Variables" tab, add attachedTo as a label.

Step 4: Set the new files
While still in your project settings, under "Script Settings" tab:
  • Change "Handle Object Collisions" to doHandleObjectCollisions_PlatformerBasePlatforms.asm. If you have previously modded this script, then you can also open the script and see where the changes are clearly marked to modify your own.
  • Change the "Compare Object Boxes" to doCompareBoundingBoxes_multiScreenPlatforms.asm
  • Change the "Handle Object Updates" to doHandleUpdateObjectsPlatform.asm
Step 5: Add the ability to jump off a platform
on the Left go to Scripts >Input Scripts > and find the script "jump_throughPlat.asm" and add the following lines after line 11
Code:
LDA attachedTo
BEQ +
    JMP +doJump
+

Now we can move on to creating your object!

Step 1: Create your object, set its bounding box, acceleration, max speed, and any other behaviours.
Step 2: In any action steps that you want the player to be able to walk on top of/be carried by this object, Make sure the "Walkable" action step flag is checked.

DONE!

But Wait, "How do I make a object that moves up and down?" you ask! Well, here's one method:

Step 1: open up the Handle Physics script, look around line 444, you will see this code:
Code:
  doneWithH:
    LDA Object_vulnerability,x
    AND #%00000001
    BEQ +skip
        ;;; What should we do if vulnerability bit 0 is flipped?
        JMP doneWithGravity
    +skip

replace it with this:

Code:
  doneWithH:
    LDA Object_vulnerability,x
    AND #%00000001
    BEQ +skip
        LDA Object_vulnerability, x
        AND #%00000010
        BEQ +notplatform
            LDA Object_y_lo,x
            ADC Object_v_speed_lo,x
            STA yHold_lo
            LDA Object_y_hi,x
            ADC Object_v_speed_hi,x
            STA Object_y_hi,x
            STA yHold_hi
        +notplatform
        JMP doneWithGravity
    +skip

Step 2: take the following 3 code snippets and save them to different .asm files in your "Game\AI_Scripts\" Folder. then set them as AI behaviours in the script settings. You should also label them under "Project Labels" tab accordingly.

platformstopvert.asm
Code:
    ;STOP
    LDA #$00
    STA Object_v_speed_lo,x
    STA Object_v_speed_hi,x

platformdown.asm
Code:
    ;DOWN
    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    STA Object_v_speed_hi,x

platformup.asm
Code:
    ;UP
    LDY Object_type,x
    LDA ObjectJumpSpeedLo,y
    EOR #$FF
    STA Object_v_speed_lo,x
    LDA ObjectJumpSpeedHi,y
    EOR #$FF
    STA Object_v_speed_hi,x

Step 3: set your platform object's Jump Speed to be the speed you want the platform to move up and down at. Most people would want to set it the same as the max movement speed.

Step 4: in the action steps, set the new AI behaviours in the object details window under the Actions Tab with the Action drop Down menu. Make sure that both "Walkable" and "Ignore Gravity" are both checked!
Can't believe that finally there is a tutorial for something like this!
Thank you so much!šŸ˜
 

tbizzle

Well-known member
@SciNEStist Just like the ones from Snake's Revenge. Move left, right, up. or down. Probably could use some user screen bytes to switch up their speeds.
19-Snake_s_Revenge_235.png
 
not sure what an adventure module moving platform would look like. what are you hoping for it to do?
He's referring to this thread... I got the collision working but not the movement
 

baardbi

Well-known member
This is amazing! And it looks so smooth. Fantastic work! I will definitely play around with this in the next couple of days.
 

twin paradox

New member
Wow, can't wait to try this out! I've tried so many different methods for making moving platforms and I always had to make major concessions (can't jump while standing on them, etc). Thank you so much for this!
 
Top Bottom