[4.5.6] Monster Projectile Very Slow Speed (RESOLVED)

Necrozys

Member
Hi everyone! I made a monster weapon but it only moves one speed and it's very slow even if I raise speed to maximum. I am using the ArcadePaltformBase module.
Here are my scripts:

The script I put for the monster action to shoot (ShootAtPlayer.asm):

LDA Object_x_hi,x
;; plus x offset
STA tempA
LDA Object_y_hi,x
;; plus y offset
STA tempB
LDA #$05 ;; game object to create.
STA tempC
LDA #$00 ;; action step for that object
STA tempD
LDA Object_screen,x
STA tempz

CreateObjectOnScreen tempA, tempB, tempC, tempD, tempz

The weapon creates itself no problem.

The script I put for the weapon action, I want the shot to go towards the player (MoveTowardsPlayer.asm)

;;; aim towards player.
TYA
PHA
TXA
PHA
STA tempx

LDA Object_x_hi,x
STA tempA
LDA Object_y_hi,x
STA tempB
LDX player1_object
LDA Object_x_hi,x
STA tempC
LDA Object_y_hi,x
STA tempD

LDX tempx

MoveTowardsPoint tempA, tempC, tempB, tempD
LDA Object_direction,x
AND #%00000111
ORA #%00001000
STA Object_direction,x

PLA
TAX
PLA
TAY

In the details I selected monster weapon. I tried maximum speed but it always moves with the same slow speed. Also in actions I selected Ignore Gravity and the action is of course MoveTowardsPlayer. My weapon as no animations.

Please let me know what I can do so that the selected speed affects the monster weapon.
 
Last edited:

Peter Schmitz

Active member
the scripts are the same as in the shmup tutorial which works fine for me. Did you give your weapon an acceleration speed? I have it set to the highest number 255
 

Peter Schmitz

Active member
okay - just tried different things but I also can't get an enemy to shoot directly at you in the platformer module. I can make it shoot left or right, but the shoot at player script in combination with the projectile moving towards the player doesn't seem to work like in the shmup module
 

dale_coop

Moderator
Staff member
It's because the physics engine ignore the speed settings for all the objects that use the "move toward player" action.
To change that, you need to modify your Handle Physics script.
NOTE: don't forget to make a backup of that script before modifying it.

Here what you could try... Edit your Physics script, locate the line:
Code:
doHandlePhysics:
and the line:
Code:
    useNormalDirectionalPhysics:

Replace ALL the code BETWEEN those two lines... with that code:
Code:
    LDA #$00
    STA collisionsToCheck ;; blank out collisions to check.
   
    ;;; check to see if we are using aiming physics.
    ;;; if we are using aim physics, Object_direction will have it's 3rd bit flipped. xxxxXxxx
    LDA Object_direction,x
    AND #%00001000
   BNE +useAimedPhysics
        JMP useNormalDirectionalPhysics
    +useAimedPhysics:
       
        LDA #%00001111
        STA collisionsToCheck
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        LSR
        LSR
        LSR
        LSR
        STA tempA ;; high byte of "speed" will determine how many times we should update move towards speed.
        ;; use aimed physics.
        ;; Aimed physics doesn't need to update speed.
        LDA Object_x_lo,x
        STA xHold_lo
        LDA Object_x_hi,x
        STA xHold_hi
       
        LDA Object_y_lo,x
        STA yHold_lo
        LDA Object_y_hi,x
        STA yHold_hi
       
        LDA Object_h_speed_lo,x
        BPL AddHspeedToAimedX
            ;; subtract h speed to aimed x
            LDA Object_h_speed_lo,x
            EOR #$FF
            STA temp
            LDY tempA
            doAimLoop1:
                LDA xHold_lo
                sec
                sbc temp
                STA xHold_lo
                LDA xHold_hi
                sbc Object_h_speed_hi,x
                STA xHold_hi
                DEY
                BPL doAimLoop1
               
               
           
            JMP figureAimedVspeed
        AddHspeedToAimedX:
            LDY tempA
            doAimLoop2:
            LDA xHold_lo
            CLC
            ADC Object_h_speed_lo,x
            STA xHold_lo
            LDA xHold_hi
            ADC Object_h_speed_hi,x
            STA xHold_hi
            DEY
            BPL doAimLoop2
       
        figureAimedVspeed:

        LDA Object_v_speed_lo,x
        BPL AddVSpeedToAimedY
            ;; subtract v speed to aimed y
            LDA Object_v_speed_lo,x
            EOR #$FF
            STA temp
            LDY tempA
            doAimLoop3:
            LDA yHold_lo
            clc
            adc temp
            STA yHold_lo
            LDA yHold_hi
            adc Object_v_speed_hi,x
            STA yHold_hi
            DEY
            BPL doAimLoop3
           
            JMP doneWithAimedV
        AddVSpeedToAimedY:
            LDY tempA
            doAimLoop4:
            LDA yHold_lo
            sec
            sbc Object_v_speed_lo,x
            STA yHold_lo
            LDA yHold_hi
            sbc Object_v_speed_hi,x
            STA yHold_hi
            DEY
            BPL doAimLoop4
        doneWithAimedV:
        ;;;;;;;;;;;;; check xHold_hi and yHold_hi against bounds.
       
            LDA yHold_hi
            CMP #BOUNDS_TOP
            BEQ +doTopBounds
            BCC +doTopBounds
                JMP +doneWithTop
            +doTopBounds
               
                    LDA #$02
                    STA screenUpdateByte
           
                    JSR doHandleBounds
                    JMP skipPhysics
                   
            +doneWithTop
       
            STA yHold_hi
            CLC
            ADC self_bottom
            CMP #BOUNDS_BOTTOM ;#240
        ;   BEQ doBottomBounds
            BCS +doBottomBounds
                JMP +doneWithBottom
            +doBottomBounds:
                    STA screenUpdateByte
                    JSR doHandleBounds
                    JMP skipPhysics
                   
            +doneWithBottom
       
       
       
                LDA xHold_hi
                clc
                ADC self_right
                BCS +doRightBounds
                    JMP +doneWithRight
                +doRightBounds:
               
                    LDA #$01
                    STA screenUpdateByte
                    JSR doHandleBounds
                    JMP skipPhysics
                   
                +doneWithRight
                LDA xHold_hi
                CMP #BOUNDS_LEFT
                BEQ +doLeftBounds
                BCC +doLeftBounds
                    JMP +doneWithLeft
                +doLeftBounds  
                       
                        LDA #$03
                        STA screenUpdateByte
                        JSR doHandleBounds
                        JMP skipPhysics
                +doneWithLeft

       
        JMP skipPhysics ;; skips all the acc/dec stuff and goes right to movement based on speed
                            ;; which was figured out in the directional macro.

If everything goes well, now the projectile should use the speed you set to to.
 

Necrozys

Member
It's because the physics engine ignore the speed settings for all the objects that use the "move toward player" action.
To change that, you need to modify your Handle Physics script.
NOTE: don't forget to make a backup of that script before modifying it.

Here what you could try... Edit your Physics script, locate the line:
Code:
doHandlePhysics:
and the line:
Code:
    useNormalDirectionalPhysics:

Replace ALL the code BETWEEN those two lines... with that code:
Code:
    LDA #$00
    STA collisionsToCheck ;; blank out collisions to check.
  
    ;;; check to see if we are using aiming physics.
    ;;; if we are using aim physics, Object_direction will have it's 3rd bit flipped. xxxxXxxx
    LDA Object_direction,x
    AND #%00001000
   BNE +useAimedPhysics
        JMP useNormalDirectionalPhysics
    +useAimedPhysics:
      
        LDA #%00001111
        STA collisionsToCheck
        LDY Object_type,x
        LDA ObjectMaxSpeed,y
        LSR
        LSR
        LSR
        LSR
        STA tempA ;; high byte of "speed" will determine how many times we should update move towards speed.
        ;; use aimed physics.
        ;; Aimed physics doesn't need to update speed.
        LDA Object_x_lo,x
        STA xHold_lo
        LDA Object_x_hi,x
        STA xHold_hi
      
        LDA Object_y_lo,x
        STA yHold_lo
        LDA Object_y_hi,x
        STA yHold_hi
      
        LDA Object_h_speed_lo,x
        BPL AddHspeedToAimedX
            ;; subtract h speed to aimed x
            LDA Object_h_speed_lo,x
            EOR #$FF
            STA temp
            LDY tempA
            doAimLoop1:
                LDA xHold_lo
                sec
                sbc temp
                STA xHold_lo
                LDA xHold_hi
                sbc Object_h_speed_hi,x
                STA xHold_hi
                DEY
                BPL doAimLoop1
              
              
          
            JMP figureAimedVspeed
        AddHspeedToAimedX:
            LDY tempA
            doAimLoop2:
            LDA xHold_lo
            CLC
            ADC Object_h_speed_lo,x
            STA xHold_lo
            LDA xHold_hi
            ADC Object_h_speed_hi,x
            STA xHold_hi
            DEY
            BPL doAimLoop2
      
        figureAimedVspeed:

        LDA Object_v_speed_lo,x
        BPL AddVSpeedToAimedY
            ;; subtract v speed to aimed y
            LDA Object_v_speed_lo,x
            EOR #$FF
            STA temp
            LDY tempA
            doAimLoop3:
            LDA yHold_lo
            clc
            adc temp
            STA yHold_lo
            LDA yHold_hi
            adc Object_v_speed_hi,x
            STA yHold_hi
            DEY
            BPL doAimLoop3
          
            JMP doneWithAimedV
        AddVSpeedToAimedY:
            LDY tempA
            doAimLoop4:
            LDA yHold_lo
            sec
            sbc Object_v_speed_lo,x
            STA yHold_lo
            LDA yHold_hi
            sbc Object_v_speed_hi,x
            STA yHold_hi
            DEY
            BPL doAimLoop4
        doneWithAimedV:
        ;;;;;;;;;;;;; check xHold_hi and yHold_hi against bounds.
      
            LDA yHold_hi
            CMP #BOUNDS_TOP
            BEQ +doTopBounds
            BCC +doTopBounds
                JMP +doneWithTop
            +doTopBounds
              
                    LDA #$02
                    STA screenUpdateByte
          
                    JSR doHandleBounds
                    JMP skipPhysics
                  
            +doneWithTop
      
            STA yHold_hi
            CLC
            ADC self_bottom
            CMP #BOUNDS_BOTTOM ;#240
        ;   BEQ doBottomBounds
            BCS +doBottomBounds
                JMP +doneWithBottom
            +doBottomBounds:
                    STA screenUpdateByte
                    JSR doHandleBounds
                    JMP skipPhysics
                  
            +doneWithBottom
      
      
      
                LDA xHold_hi
                clc
                ADC self_right
                BCS +doRightBounds
                    JMP +doneWithRight
                +doRightBounds:
              
                    LDA #$01
                    STA screenUpdateByte
                    JSR doHandleBounds
                    JMP skipPhysics
                  
                +doneWithRight
                LDA xHold_hi
                CMP #BOUNDS_LEFT
                BEQ +doLeftBounds
                BCC +doLeftBounds
                    JMP +doneWithLeft
                +doLeftBounds 
                      
                        LDA #$03
                        STA screenUpdateByte
                        JSR doHandleBounds
                        JMP skipPhysics
                +doneWithLeft

      
        JMP skipPhysics ;; skips all the acc/dec stuff and goes right to movement based on speed
                            ;; which was figured out in the directional macro.

If everything goes well, now the projectile should use the speed you set to to.
Your the man Dale! It works like a charm. Thank you!
 
Top Bottom