I’m new to UE4 and blue printing and not a quite experienced programmer.
I’m making a space shooter and I want to have a power up that changes the fire rate of the bullets for a period of time e.g. five seconds.
I’ve made a function named PowerUpFireRate, where I change the rate of fire, but I want to be accessed for a period of time and then reset the fire rate.
I’ve experimented with timer and timelines but I couldn’t find a solution.
you should show your code for firing and for firerate so we have a frame of reference to work from. it could be as simple as having the powerup change a firerate variable, delay, return firerate to normal. without knowing your setup though its hard to say do X.
I created a fire control event in the bpPlayer. Then I created a function what I pass by the bpProjectileSpawn and the Weapon.
I read about that a timeline should do the trick by I the bullets a fired automatically, and I want the while the left mouse button is pressed and faster than it supposed to. The normal fire rate is 0.4 and I want to be 0.2
Thank you in advance!
seems overly complex to me. really all you need to be doing is setting the firerate or rather adjusting the time between when shots are fired. in your example your constantly setting and unsetting things and working with cooldowns which seems like a pain to me. now im not saying that this is the only way to do things but its just a simple way to accomplish what your looking to do and could be adapted to work with your system quite easily.
what i did below as a quick example setup was to create a simple firing loop where the fire rate is the delay between shots. its a pretty simple easy to understand setup. then to modify the firerate we use a script in the powerup itself. this script simply gets the current fire rate and doubles it, delays, then halves the firerate (working in delays here so firerate / 2 will fire more bullets). now im sure there may be some needed clamping and other checks but its the idea at its simplest.
for your use case you could have a multiplier which affects delta seconds. so you would have primary firerate - (delta seconds * rate modifier). this would in essence change your firerate.
Okay, from what I’m seeing your firing system seems super complex when what it sounds like you are trying to achieve doesn’t have to be. I also don’t know the intricacies of your setup (do you have animations that control firing at all, potentially using anim montages for recoil?). I am going to assume that you are using a very basic setup and don’t rely on animations at all. If so, what you can do is simply set up a fire timer that fires while you have the button held down similar to what is explained here:
You can then hook up your primary fire to the auto fire event and before actually firing the bullet, check if the player is still holding down the button. From now on you can simply adjust one variable in your BP to modify fire rate. So a fire rate increase event would be as simple as setting the fire rate variable to a value that reflects the increase you want to see.
If you want a set duration for the buff, you can use a delay node, or setup another timer and event. The implementation would be:
- Store the old fire rate in a variable so you don’t lose it
- Set the fire rate to the buffed value
- Delay for the duration of the buff
- Reset the fire rate to the old fire rate
I hope this answers your question
Looks like you have a good amount of help from the prior posts but I thought since you mentioned you’re a beginner making a space shooter you may be interested in checking out this space shooter template I made and you can download for free.
You may also be interested in this beginner series to help with creating a lot of the basic game play mechanics in blueprints.
Thanks a lot everyone!!! that was a great help. I will check it out!!!