Announcement

Collapse
No announcement yet.

Have weapon fire rate faster than tick

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Have weapon fire rate faster than tick

    I've been really careful trying to make sure any calculations I've been doing regarding physics, health regen, etc. utilises delta time in some way to keep things independent from the frame rate. However I've run into a bit of an issue I can't seem to resolve, and I'm surprised there hasn't been a single thread on the issue, even from complete beginners.

    How can you make a weapon fire at the same speed REGARDLESS of the tick rate?

    Mind you, my system EASILY handles UE4 at 60fps, but not everyone has that luxury. And I know, a weapon firing more than 60 times per second seems STUPIDLY high, but it's still a problem if you had a minigun that has a high fire rate.

    Any ideas on solving this issue, or am I just gonna have to make sure any and all weapons I ever create never fire faster than the absolute lowest fps I can see someone getting in the engine?

    #2
    You turn on sub-stepping.

    Comment


      #3
      Hi SirChronocide,

      Try using timers instead of tick. You can set timers to fire off at specific intervals, even if the intervals are extremely short. To get a firemode roughly the equivalent of 60 fps, try .08 and set it to looping. See if this works for what you are looking for.
      Adam Davis | Marketplace Support | Epic Games
      How to report a bug? | Installation & Setup issues? | Answerhub Bug Reports | Twitter

      Comment


        #4
        Originally posted by Adam Davis View Post
        Hi SirChronocide,

        Try using timers instead of tick. You can set timers to fire off at specific intervals, even if the intervals are extremely short. To get a firemode roughly the equivalent of 60 fps, try .08 and set it to looping. See if this works for what you are looking for.
        It is worth noting that timers cannot fire off at intervals higher than the Tick rate. Example (outputting GetWorld()->GetTimeSeconds() when the timer fires):

        Click image for larger version

Name:	Untitled.png
Views:	1
Size:	290.5 KB
ID:	1113602

        Comment


          #5
          Originally posted by Adam Davis View Post
          Hi SirChronocide,

          Try using timers instead of tick. You can set timers to fire off at specific intervals, even if the intervals are extremely short. To get a firemode roughly the equivalent of 60 fps, try .08 and set it to looping. See if this works for what you are looking for.
          Sorry, should've mentioned this more specifically. I am NOT tying anything to Tick; I avoid it as MUCH as possible. I use timelines and timers wherever I can and it seems like it doesn't make a difference.

          When I get an fire input, I set a boolean isFiring to true, start my firing timeline, and have it check if that boolean is true and have it iterate through my usual firing procedure; then adds I add a delay equal to the firerate/sec (for example 0.1). After the delay, it loops back into the initial isFiring check. Once isFiring is set the false, it stops the timeline.

          Comment


            #6
            Just use timers.

            It is worth noting that timers cannot fire off at intervals higher than the Tick rate. Example (outputting GetWorld()->GetTimeSeconds() when the timer fires):
            I'm assuming that's because GetTimeSeconds() gets updated once each tick, not because the timer doesn't work faster than frame rate.

            Take a look at this, let's assume you want a minigun shooting 6000 rounds per minute. That's 100 per second, but since this is a very fast minigun it's going to shoot 1000 rounds per second, just because I get framerates in the hundreds.

            Click image for larger version

Name:	fast timers.jpg
Views:	1
Size:	170.6 KB
ID:	1113675

            As you can see, the shooting event gets called 5000 times in the span of 5 seconds, a lot more than once per tick. A thing to note is that since you're dealing with very small floating point numbers you'll get some errors, in my tests I got numbers like 5002 or 5003 instead of just 5000.
            sybloom ::: Website Coming Soon

            Comment


              #7
              Originally posted by 修羅 View Post
              Just use timers.


              I'm assuming that's because GetTimeSeconds() gets updated once each tick, not because the timer doesn't work faster than frame rate.

              Take a look at this, let's assume you want a minigun shooting 6000 rounds per minute. That's 100 per second, but since this is a very fast minigun it's going to shoot 1000 rounds per second, just because I get framerates in the hundreds.

              [ATTACH=CONFIG]106056[/ATTACH]

              As you can see, the shooting event gets called 5000 times in the span of 5 seconds, a lot more than once per tick. A thing to note is that since you're dealing with very small floating point numbers you'll get some errors, in my tests I got numbers like 5002 or 5003 instead of just 5000.
              This is wrong. The event will be called 5001 times in one frame. You can call an event more than once in a frame, but you can't call it between N - N + 0.0166667 space. I hope someone corrects me because I kinda need it myself personally.
              Last edited by Achilleon; 08-13-2016, 05:31 AM.
              Fighting Game Template: PROJECT: Unreal Fighter 2D

              Comment


                #8
                Uhm i understand your problem, but that timer solution sounds... strange? to me.

                At 60 FPS with a Target of 6.000 Bullets/s:
                100 / Delta Time = X
                => Shoot X Bullets / Tick

                I mean, wheres the difference if you shoot 100 bullets / tick or 100 bullets between ticks, it does get rendered only 1 time each tick anyway...?
                That's why the delta time is there, to calculate such stuff. No need for threaded timers.
                Last edited by KrautPotato; 08-13-2016, 07:01 AM.
                @CarstenZarbock - Follow me on Twitter, thank you

                Comment


                  #9
                  Originally posted by Achilleon View Post
                  This is wrong. The event will be called 5001 times in one frame. You can call an event more than once in a frame, but you can't call it between N - N + 0.0166667 space. I hope someone corrects me because I kinda need it myself personally.
                  Not sure if I follow you. What SirChronocide asked for was a way to call functions at an arbitrary interval regardless of framerate and that's what timers do.

                  Originally posted by KrautPotato View Post
                  I mean, wheres the difference if you shoot 100 bullets / tick or 100 bullets between ticks, it does get rendered only 1 time each tick anyway...?
                  That's why the delta time is there, to calculate such stuff. No need for threaded timers.
                  Agree, calculating the number of bullets that should be spawned on each tick depending on delta time is the more sensible choice. But if for some reason he really needs to call events on micro intervals it's good to know that timers work and are very reliable.
                  sybloom ::: Website Coming Soon

                  Comment


                    #10
                    Timers are better. As soon as you start using things like Custom Time Dilation, The Tick Event starts behaving differently.

                    If you want projectiles to fire *that* quickly, you need some kind of substepping system, where you break up a frame into multiple chunks and spawn the projectiles in offset positions accordingly.

                    Comment


                      #11
                      Originally posted by 修羅 View Post
                      Not sure if I follow you. What SirChronocide asked for was a way to call functions at an arbitrary interval regardless of framerate and that's what timers do.


                      Agree, calculating the number of bullets that should be spawned on each tick depending on delta time is the more sensible choice. But if for some reason he really needs to call events on micro intervals it's good to know that timers work and are very reliable.
                      Problem is he is trying to make a minigun. And if he uses timer or timeline, every event will be triggered on every frame minimum. So if you arrange a timer that triggers 2 times each 0.008 seconds, the event will trigger only once. If you make it very small, such as 0.001 seconds, it will trigger twice in the same frame and this will still cause the event to trigger 2 times at the same time just duplicating the event, sound, hit, etc.

                      I will be honest though, a minigun that is firing each 0.0166667 seconds is still fast. :P
                      Fighting Game Template: PROJECT: Unreal Fighter 2D

                      Comment

                      Working...
                      X