Lethn that's pretty much what i ended up going for!! I made a timer that starts when the reload() function is triggered and only finishes the reload once the timer finishes and sends the timeout signal. If the weapon is fired while the timer is still counting in gets stopped
Ggorrrroto
- Mar 6, 2023
- Joined Feb 26, 2023
- 0 best answers
gorrrroto i can probably get away with implementing whatever i need without making use of state machines but it'd be nice to hear what the more experienced among you fellow devs have to say
Pretty much what the title says, i'm trying to code the weapons of a game and now that i've started implementing the reload mechanic i've started to wonder if should give the weapons a state machine to for example be able to cancel the reload if i fire while the reload is happening or other similar stuff.
Has anyone encountered the same issue? What is the best solution for it in your experience?DaveTheCoder for now im making the instancing loop before sending in the signal but i'll probably try sending the packed scene in the future, thanks for suggestion
gorrrroto okay little update, since i was working with the same bullet instance i presume its getting all confused, I'll try sending an array with all the bullet instances in the signal
Bilal tried it and still the same outcome
I'll try more stuff, lets hope something works
im thinking the code maybe overrides the changes made to previous projectiles but im not too sure, i'll maybe try first adding them to an array to later modify their characteristics more clearly, lets hope it helps
Okay so im trying to code a weapon and projectile managing system, for this i've made the weapons send a signal containing the information of the projectile such as how much it should spread or the amount of projectiles fired per shot(to make a shotgun for instance). The following code on the node is in charge off spawning said projectiles, it works just fine when firing single projectiles per shot but once i try to spawn more than one projectile per shot and iterate through the code all of the bullets spawned have the exact same direction and rotation, any ideas of why this may be? Thanks in advance!
extends Node var rng = RandomNumberGenerator.new() func handle_projectile_spawn(projectile, position, direction, projectile_amount, projectile_spread_angle): for i in projectile_amount: var spread_angle = deg2rad(projectile_spread_angle)/2 direction = direction.angle() direction = rng.randf_range((direction+spread_angle), (direction-spread_angle)) direction = Vector2(cos(direction), sin(direction)) add_child(projectile) projectile.global_position = position projectile.set_direction(direction) print("bullet ", i, " fired, direction ", direction)