Projectile Origin Inquiry [SOLVED]

PortableAnswers

New member
:?:
How can you adjust the projectile's origin point? For example, my player is shooting from his head instead of the weapon that he is holding.
 

dale_coop

Moderator
Staff member
You need to ajust the temp value in your script.
Which script do you use for shoot weapon? (which module?)
 

PortableAnswers

New member
dale_coop said:
You need to ajust the temp value in your script.
Which script do you use for shoot weapon? (which module?)

Could you please provide an example of which temp values to alter? Do I replace the X values with integers?
I am using v4.0.6, AdventureModule.MOD, and "a_create_projectile.asm" script.
 

dale_coop

Moderator
Staff member
Code:
	LDA Object_x_hi,x
	;;; offset x for creation
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon from your player/monster (change the value to adjust)
	STA temp
	LDA Object_y_hi,x
	CLC
	ADC #$04    ;;<<-- vertical offset of your weapon from your player/monster (change the value to adjust)
	STA temp1
First, you can change the value ("#$04" to anything you want: #$00 or #$01, #$02, #$03...#$09, #$0A, ...#$0F)
Currenlty the origin (offset) is unique, always the same place... even if your player facing left, or right, or top or down.
But I think you would like it to be the right place in every directions (like the sword does), it would require more modifications to the script.

Or maybe you could made the origin the center of your player?


Do you use the "Melee" and "Projectile" game objects in your game?
If not, you could use those objets for your projectile.
The benefice is that you can choose precisely the origin where those objects are created, for each facing direction of the Player.
 

PortableAnswers

New member
Thank you for the information! With your advice, I was able to get the proper placement for one of the directions.
Yes, the static origin will be an issue for my character as his blaster weapon is essential to his design. I will need to have an origin point for each direction.
I have messed around with the melee weapon but I do not know how to get it to "shoot" forward like a projectile. Basically, I am trying to shoot a bullet for a gun and the end of the barrel is at a different X and Y point for each direction. Also, I see that we are discussing in another post. I will keep my replies to this post from now on :)
 

dale_coop

Moderator
Staff member
OK.
Do you use the "Melee" and "Projectile" game objects in your game?
If not, you could use those objets for your projectile.
The benefice is that you can choose precisely the origin where those objects are created, for each facing direction of the Player.
 

PortableAnswers

New member
I understand the concept of using "Melee" as I followed the Adventure tutorial and created the sword that you can set it's placement under Game Objects. If I use "Melee" for my projectile then how do I get the projectile to move forward? I.E. the gun's bullet shoots away from the direction that I am facing.
 

dale_coop

Moderator
Staff member
Ok, if you really want to use the "a_createprojectile.asm", you would need to modify it and set the offset for each direction.
(Make a copy of the "a_createprojectile.asm" as a backup before modify it)
I am not home, so I can't test, but the script should be something like that:
Code:
 LDA gameHandler
    AND #%00100000
    BEQ notNPCstate_proj
 JMP doneShooting
 notNPCstate_proj
 LDA weaponsUnlocked
 AND #%00000010
 BNE canShoot
 JMP doneShooting
canShoot:
LDX player1_object
 GetCurrentActionType player1_object


 CMP #$02
 BNE notAlreadyShooting
 JMP doneShooting 
notAlreadyShooting
 ;;; don't attack if already attacking.
 ;;; do we have to check for hurt here?
 ;;;;; Here, we WOULD create melee
 ChangeObjectState #$02, #$02
 LDA Object_movement,x
 AND #%00001111
 STA Object_movement,x
 LDA #$00
 STA Object_h_speed_hi,x
 STA Object_h_speed_lo,x
 STA Object_v_speed_hi,x
 STA Object_v_speed_lo,x
 
 
 LDA Object_x_hi,x
 STA temp
 LDA Object_y_hi,x
 STA temp1
 
    LDA Object_movement,x
    AND #%00000111
	STA temp2
	CMP FACE_LEFT
	BEQ setLEFTOffsetProjectile
	CMP FACE_RIGHT
	BEQ setRIGHTOffsetProjectile
	CMP FACE_UP
	BEQ setUPOffsetProjectile
	CMP FACE_DOWN
	BEQ setDOWNOffsetProjectile
	JMP doneShooting
	
setLEFTOffsetProjectile:
	LDA Object_x_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing left (change the value to adjust)
	STA temp
	LDA Object_y_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon  when your player facing left(change the value to adjust)
	STA temp1
	JMP continueCreatingProjectile
	
setRIGHTOffsetProjectile:
	LDA Object_x_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing right (change the value to adjust)
	STA temp
	LDA Object_y_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing right (change the value to adjust)
	STA temp1	
	JMP continueCreatingProjectile

setUPOffsetProjectile:
	LDA Object_x_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing up (change the value to adjust)
	STA temp
	LDA Object_y_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing up (change the value to adjust)
	STA temp1	
	JMP continueCreatingProjectile

setDOWNOffsetProjectile:
	LDA Object_x_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing down (change the value to adjust)
	STA temp
	LDA Object_y_hi,x
	CLC
	ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing down (change the value to adjust)
	STA temp1	
	JMP continueCreatingProjectile
	
continueCreatingProjectile:
	CreateObject temp, temp1, #$03, #$00 
 
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    LDY temp2
    LDA directionTable,y
    ORA Object_movement,x
    STA Object_movement,x
    PlaySound #sfx_shoot
	 
doneShooting:
	RTS

If you want, if it doesn't work, I could test tonight... (when I am home. Now I am at my job, don't have NESMaker with me to test)
 

PortableAnswers

New member
Well, it's not necessarily that I really want to use "a_createprojectile.asm", it's just that I am not yet fluent in 6502. I am not too sure how to implement the code that you provided. If you do get a chance to test it, that would be great! Thank you for all of your help.
 

dale_coop

Moderator
Staff member
PortableAnswers said:
Well, it's not necessarily that I really want to use "a_createprojectile.asm", it's just that I am not fluent in 6502. I am not too sure how to implement the code that you provided. If you do get a chance to test it, that would be great! Thank you for all of your help.

I understand... Please, try the script, test with different values, for each direction, to see the difference/the impact.

Tonight, I will try to make some tests with the script too (to validate)
And I will try to see if/how we could use "Melee" as your blaster projectile.
 

dale_coop

Moderator
Staff member
I made some small tests...
With melee, it's not so easy to align correctly the object with the player, it doesn't work well, as it.

This script for a_create_projectile.asm work quite good:
Code:
createWeaponProjectile:
 LDA gameHandler
    AND #%00100000
    BEQ notNPCstate_proj
 JMP doneShooting
 notNPCstate_proj
 LDA weaponsUnlocked
 AND #%00000010
 BNE canShoot
 JMP doneShooting
canShoot:
LDX player1_object
 GetCurrentActionType player1_object


 CMP #$02
 BNE notAlreadyShooting
 JMP doneShooting
notAlreadyShooting
 ;;; don't attack if already attacking.
 ;;; do we have to check for hurt here?
 ;;;;; Here, we WOULD create melee
 ChangeObjectState #$02, #$02
 LDA Object_movement,x
 AND #%00001111
 STA Object_movement,x
 LDA #$00
 STA Object_h_speed_hi,x
 STA Object_h_speed_lo,x
 STA Object_v_speed_hi,x
 STA Object_v_speed_lo,x
 
 
 LDA Object_x_hi,x
 STA temp
 LDA Object_y_hi,x
 STA temp1
 
    LDA Object_movement,x
    AND #%00000111
    STA temp2
    CMP #%00000110
    BEQ setLEFTOffsetProjectile
    CMP #%00000010
    BEQ setRIGHTOffsetProjectile
    CMP #%00000100
    BEQ setUPOffsetProjectile
    CMP #%00000000
    BEQ setDOWNOffsetProjectile
    JMP doneShooting
    
setLEFTOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    SBC #$0D    ;;<<-- horizontal offset of your weapon when your player facing left (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    ADC #$04    ;;<<-- vertical offset of your weapon  when your player facing left(change the value to adjust from #$00 to #$0F or more)
    STA temp1
    JMP continueCreatingProjectile
    
setRIGHTOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    ADC #$0D    ;;<<-- horizontal offset of your weapon when your player facing right (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    ADC #$04    ;;<<-- vertical offset of your weapon when your player facing right (change the value to adjust from #$00 to #$0F or more)
    STA temp1
    JMP continueCreatingProjectile

setUPOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing up (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    SBC #$0D    ;;<<-- vertical offset of your weapon when your player facing up (change the value to adjust) from #$00 to #$0F or more
    STA temp1
    JMP continueCreatingProjectile

setDOWNOffsetProjectile:
    LDA Object_x_hi,x
    CLC
    ADC #$04    ;;<<-- horizontal offset of your weapon when your player facing down (change the value to adjust from #$00 to #$0F or more)
    STA temp
    LDA Object_y_hi,x
    CLC
    ADC #$0D    ;;<<-- vertical offset of your weapon when your player facing down (change the value to adjust from #$00 to #$0F or more)
    STA temp1
    JMP continueCreatingProjectile
    
continueCreatingProjectile:
    CreateObject temp, temp1, #$03, #$00
 
    ;;;; x is now the newly created object's x.
    LDA Object_movement,x
    ORA temp2
    STA Object_movement,x
    LDY temp2
    LDA directionTable,y
    ORA Object_movement,x
    STA Object_movement,x
    PlaySound #sfx_shoot
 
doneShooting:
RTS


;;000 down
;010 right
;100 up
;110 left

Just make some tests, adjusting the values (testing one direction at a time)
I am sure, something easier might come in a next version of NESMaker.
 

PortableAnswers

New member
Dale_coop, this worked fantastically! Although I was unable to get the UP coordinates pixel-perfect to where I wanted them, it is a feat nonetheless and I'm sure it can be fine-tuned more in the future. Thank you very much! Any advice going forward? I'm going to study the Easy 6502 tutorial on skilldrick by Nick Morgan today.
 

dale_coop

Moderator
Staff member
Glad it helped!
Great the 6502 lessons... And more about ASM in NESMaker: https://vimeo.com/joegranatoiv (Joe made some videos about coding in nesmkaer some months ago, with the beta... but a lot of those concepts still remain)
 
Top Bottom