Just installed Unreal this weekend and I figured a fun first project would be to make a “rocket” with “fuel” that launches when I press a button.
What I have at this point is a Box object that triggers adding a force vector for 10 seconds (or how ever long the Fuel variables lasts). I set up the scenario as follows:
Box is 1 kg
Fuel = 100, subtract 10 fuel / second.
Thrust vector is (0,0,1000) since gravity appears to be (0,0,-980)
Initially, I was multiplying the force vector by the Delta Seconds variable from the ‘Event Tick’ block before it was given to AddForce but this doesn’t seem to be working. After removing that and just calling AddForce with the force vector directly, things seem to be working as expected, but I don’t understand why.
How do I use AddForce correctly in the scenario I am describing? Why wouldn’t I scale the force vector by the Delta Seconds?
I figured out that I can use the AddImpulse function and multiply it by the Delta Seconds variable to get the effect I want. After some more digging, the thread here went in to a little more detail which made sense.
AddForce is adding a force vector, which is designed to be applied regardless of the time it took to execute each frame. Something I hadn’t thought of before, but this means that when the framerate is high, the forces are higher and vice versa. In contrast, the impulse is changing the velocity of the object instantaneously. This way, we can specify the force per second we wanted, scale it to the amount of time that has passed, and apply that as an impulse.
In this way, if there are 60 frames in a second, the impulse solution will apply 1/60 of the force to be delivered per frame. The AddForce solution will apply a given force 1 time per frame. If the force per frame is 1/60th of the amount we want per second, that is fine, since we will have 60 frames * 1/60 the desired force per frame = 1 desired force. If the frame rate fluctuates to 30 though, the force solution will apply 30 frames * 1/60 the desired force per frame = 0.5 desired force. The impulse solution, in contrast, will apply 1/30th of the desired force per frame when the frame rate is 30, which will give the intended results.
I had a similar problem but flipped… because i had high FPS (100-110) the input force to the AddForce Node was smaller… but when the game was run on a lower end PC (20-30 fps) the input force was much greater, because the delta time was also greater… this provoced inconsistense and made the input forces be dependent of the frames of the machine.
I replaced the AddForce node with AddImpulse and it’s working as intended… but waht is the purpose of the AddForce node if is not to use it on each frame? (because using AddForce makes it non frame-independent)
One workaround is to clamp the World Delta between 1 and some large number, this way it functions as intended on fast fps while still getting the benefit of working on slow fps.