Trying to make an automatic gun

In the game I’m trying to make I’m firing the gun using a raycast code but I can’t find out a way to loop it so when I hold down left click it will keep firing like an automatic gun.

This should work OK:

Thank you so much!

This might actually answer a long standing question of mine.

Is this solution going to vary with an unstable framerate?

It’s frame-rate independent. Although a timer running *faster *than the framerate may not work as you expect.

Good answer. I usually call the custom event right before the timer. Otherwise, it will wait until the first instance, which makes the gun look delayed.

I’ll post some BP’s tomorrow with Single, Burst and Auto firing modes (frame rate independent).

Hence the -.1

Are delay nodes also frame rate independent?

Yes, they operate in seconds. Delay is not *that *much different from a Timer. But there’s little else you can do with a Delay node apart from having it ‘execute things later’. You can’t cancel / query Delay, for example. The Return Value pin of the timer gives you the control a Delay node is hiding under the hood.

For some reason seeing Tick connected to Delay makes me feel uneasy :expressionless:

Here’s the BP pic I promised.

Character executes a Fire Weapon event in the gun class. Gun class handles the logic and projectile spawning.

@Everynone very cool how you can offset the timer start in the negative like that. I was hoping this could fix my specific problem, in the thread here: Low FPS values shorten jump height, but lengthen timers? - Blueprint Visual Scripting - Unreal Engine Forums but it didn’t seem to. Do you know of a way to eliminate the frame of delay I’m experiencing? Or should I just resign myself to using manual timers on tick?

sorry to hi-jack this thread :confused:

If you’re experience a delay with the negative Initial Start Delay equal to Time, then consider firing the associated event directly right after (or even before) the timer itself:

In which case no delay is needed, ofc.

@Everynone the problem I’m dealing with is that the timers appear to call their function a frame later than they should, resulting in different stop times depending on FPS. If you try this simple scenario in the ThirdPerson example I have here, you can see what I mean. It doesn’t have to do with a delay in the timer itself starting, afaik.


Then if you place yourself at the side of the geometry in the level, and roll 3 times, once at 60fps, once at 30fps, and once at 10fps, you will get varying results:

method1result.jpg

I will need to continue in another post, since it won’t let me add any more images.

Continued,

Now using this other method, which is just a custom timer using event tick and deltaseconds, you’ll see the end positions are all uniform:



method2 result.jpg

This is what I mean. There seems to be an issue with the timers specifically, and I’ve tried a bunch of things to fix this with no luck.