Projectile not in middle of character [4.59]

BenjiBro

New member
bn_problem2.pngFor some reason my projectiles keep being instantiated on one side of the player instead of depending on where he's facing, I know the animations work, just don't know how to make it even.
 

Attachments

  • bn_problem.png
    bn_problem.png
    9.5 KB · Views: 1

dale_coop

Moderator
Staff member
If you use the default shootProjectile input script from the metroidvania module, yes... that scripts, actually creates the projectile object on one side (a few pixels to the right from the left side of the player object).

In order to have it correctly placed, you will need to modify the script... checking the current facing of your player and adjust the placement of the projectile (adding/subtracting a few pixels) according to it.

what is the size of your player object?
could you share the script you are using?
 

BenjiBro

New member
2 by 3 tiles and here's the script:
HTML clipboard
;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.
;;; Assumes variable called myAmmo exists.
;;; assumes myAmmo is in hud element 8.
LDA myAmmo
BNE +canShootMega
LDA #$01 ;; assumes normal projectile is in 1
STA tempz ;; we will use tempz to hold which type of projectile.
;;; if I had no special ammo, i'll just use normal projectile
JMP +shootThing
+canShootMega:
;;; but if i DID have ammo, I'll shoot mega shot!
LDA #$02 ;; assumes mega projectile is in 2.
STA tempz
;; there is ammo here.
DEC myAmmo
; UpdateHudElement #$03 ;; change this to which element shows myAmmo.
+shootThing
TXA
PHA
TYA
PHA
LDX player1_object
LDA Object_x_hi,x
CLC
ADC #$00
STA tempA


LDA Object_screen,x
ADC #$00
STA tempD
LDA Object_y_hi,x
CLC
ADC #$04
STA tempB
LDA Object_direction,x
AND #%00000111
STA tempC
CreateObjectOnScreen tempA, tempB, tempz, #$00, tempD
;;; x, y, object, starting action.
;;; and now with that object, copy the player's
;;; direction and start it moving that way.
LDA tempC
STA Object_direction,x
TAY
LDA DirectionTableOrdered,y
STA temp1
TXA
STA temp
StartMoving temp, temp1
PLA
TAY
PLA
TAX


+canNotShoot:
RTS
 

dale_coop

Moderator
Staff member
Here a modified script that will take the facing direction in consideration:
Code:
;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.
;;; Assumes variable called myAmmo exists.
;;; assumes myAmmo is in hud element 8.
    LDA myAmmo
    BNE +canShootMega
        LDA #$01 ;; assumes normal projectile is in 1
        STA tempz ;; we will use tempz to hold which type of projectile.
                    ;;; if I had no special ammo, i'll just use normal projectile
        JMP +shootThing
    +canShootMega:
        ;;; but if i DID have ammo, I'll shoot mega shot!
        LDA #$02 ;; assumes mega projectile is in 2.
        STA tempz
    ;; there is ammo here.
    DEC myAmmo
  ;  UpdateHudElement #$03 ;; change this to which element shows myAmmo.
    +shootThing
    TXA
    PHA
    TYA
    PHA
        LDX player1_object
        
        LDA Object_direction,x
        AND #%00000111
        CMP #FACE_LEFT
        BEQ +playerFacingLeft
        ;; else player is facing right:
        +playerFacingRight:
            ;; determining the projectile horizontal origin when the player's facing right:
            LDA Object_x_hi,x
            CLC
            ADC #$0A        ;; HERE to adjust the horiz offset (you can try different values 01,02,...08,09,0A,0B,...,0F,10,11,12...)
            STA tempA
            LDA Object_screen,x
            ADC #$00
            STA tempD
            JMP +continue
        +playerFacingLeft:
            ;; determining the projectile horizontal origin when the player's facing right:
            LDA Object_x_hi,x
            CLC
            ADC #$00    ;; HERE to adjust the horiz offset
            STA tempA
            LDA Object_screen,x
            ADC #$00
            STA tempD
        +continue:
        
        LDA Object_y_hi,x
        CLC
        ADC #$04
        STA tempB       
        LDA Object_direction,x
        AND #%00000111
        STA tempC
        CreateObjectOnScreen tempA, tempB, tempz, #$00, tempD
            ;;; x, y, object, starting action.
            ;;; and now with that object, copy the player's
            ;;; direction and start it moving that way.
            LDA tempC
            STA Object_direction,x
            TAY
            LDA DirectionTableOrdered,y
            STA temp1
            TXA
            STA temp
            StartMoving temp, temp1
    PLA
    TAY
    PLA
    TAX
+canNotShoot:
    RTS
 

BenjiBro

New member
I got it working better with this code! Thanks!
Here a modified script that will take the facing direction in consideration:
Code:
;;; Create a Projectile.
;;; Assumes that the projectile you want to create is in GameObject Slot 01.
;;; Assumes variable called myAmmo exists.
;;; assumes myAmmo is in hud element 8.
    LDA myAmmo
    BNE +canShootMega
        LDA #$01 ;; assumes normal projectile is in 1
        STA tempz ;; we will use tempz to hold which type of projectile.
                    ;;; if I had no special ammo, i'll just use normal projectile
        JMP +shootThing
    +canShootMega:
        ;;; but if i DID have ammo, I'll shoot mega shot!
        LDA #$02 ;; assumes mega projectile is in 2.
        STA tempz
    ;; there is ammo here.
    DEC myAmmo
  ;  UpdateHudElement #$03 ;; change this to which element shows myAmmo.
    +shootThing
    TXA
    PHA
    TYA
    PHA
        LDX player1_object
       
        LDA Object_direction,x
        AND #%00000111
        CMP #FACE_LEFT
        BEQ +playerFacingLeft
        ;; else player is facing right:
        +playerFacingRight:
            ;; determining the projectile horizontal origin when the player's facing right:
            LDA Object_x_hi,x
            CLC
            ADC #$0A        ;; HERE to adjust the horiz offset (you can try different values 01,02,...08,09,0A,0B,...,0F,10,11,12...)
            STA tempA
            LDA Object_screen,x
            ADC #$00
            STA tempD
            JMP +continue
        +playerFacingLeft:
            ;; determining the projectile horizontal origin when the player's facing right:
            LDA Object_x_hi,x
            CLC
            ADC #$00    ;; HERE to adjust the horiz offset
            STA tempA
            LDA Object_screen,x
            ADC #$00
            STA tempD
        +continue:
       
        LDA Object_y_hi,x
        CLC
        ADC #$04
        STA tempB      
        LDA Object_direction,x
        AND #%00000111
        STA tempC
        CreateObjectOnScreen tempA, tempB, tempz, #$00, tempD
            ;;; x, y, object, starting action.
            ;;; and now with that object, copy the player's
            ;;; direction and start it moving that way.
            LDA tempC
            STA Object_direction,x
            TAY
            LDA DirectionTableOrdered,y
            STA temp1
            TXA
            STA temp
            StartMoving temp, temp1
    PLA
    TAY
    PLA
    TAX
+canNotShoot:
    RTS
I got it working better with this code! Thanks!
 

dale_coop

Moderator
Staff member
You can adjust the offset value if you need the projectile closer or further check (my “HERE” comments in the code)
 

BenjiBro

New member
You can adjust the offset value if you need the projectile closer or further check (my “HERE” comments in the code)
Is there a way to stop the player from moving while attacking and animating the attack? I've tried the stop moving input scripts and they don't seem to work and none of the action steps seem to be related to the attack. I'll try putting some of the stop input code into the attack script.
 

dale_coop

Moderator
Staff member
Sure, check my answer here:
 
Top Bottom