Title says all. How would I go about coding an upgrade where after the player character picks it up, they temporarily get the ability to fire 3 shots. One shot would fly forward and the other two would fly in a diagonal manner.
Many ways.
1 - use node3Ds that spawn shots in different directions. When getting triple shot:
A - add a scene with the 3.
or
B - add 2 extra shooters (node3Ds)
2 - with code, run your shooting on a for loop and spawn N number of projectiles, you can at this point change their direction, which would allow you to make other fire modes like in a circle, two shot, etc.
3 - Just hard-code every projectile in the current fire-mode. When in triple shot, spawn 3 projectiles in X, Y and Z directions.
For time, I've seen many people use timers. You could instead have a "special ammo" and when it runs out it stops the triple shot, like in metal slug.
Of course your weapon system must be a "state machine", as in, you have an int
that can be 0,1,2,etc, and each is a different weapon. Then when you press the FIRE button, use a match
to run code for the current weapon.
Edit: I said node3D maybe because I'm used to working with those, but if you are in working in 2D you would use node2D instead.
Jodyjoe you could have a state machine that, upon picking up a triple-shot powerup, changes the weapon state to where you shoot a triple shot instead of one. Simple as:
export var _weaponState : int = 0 ## export so you can test different states, change this number when entering powerup areas
enum _WEAPONSTATES {SINGLE, DOUBLE, TRIPLE} ## enum to determine weapon states
func _weaponStateMachine(): ## plug this into your attack function, determines weapon state
match _weaponState:
_WEAPONSTATES.SINGLE:
## single shot attack
_WEAPONSTATES.DOUBLE:
## double shot attack
_WEAPONSTATES.TRIPLE:
## triple shot attack
Also, bonus since I've programmed this projectile behavior before: (you'll probably want to adjust values for your project)
_bullet.position.x+1 ## is right, center projectile movement
_bullet.position.x+1, _bullet.position.y+1 ## is down-right diagonal moving
_bullet.position.x+1, _bullet.position.y-1 ## is up-right diagonal moving
Would it be alright if I posted what I've coded so far in my game regarding the shooting and powerups? I think it would be helpful with pointing out what code I can add to what I already have.
Jodyjoe
Would it be alright if I shared what I've coded so far in my game regarding the shooting and powerups? I think it would be helpful with pointing out what code I can add to what I already have coded.
Pender definitely.
© 2022 - 2024 — McMap. All rights reserved.