Get (previous) velocity on hit.

I have a physics projectile which has an On Hit event. When the hit event fires, I wish to get the direction the projectile was traveling, but that has proved surprisingly difficult.
I can get the velocity of the projectile with the “get component velocity” node, however since the hit event has already happened, the projectile has now changed its velocity. I need the velocity, or direction, the moment before the hit event.

vel traces.png

#1 are traces gotten with the get velocity node each tick. Note that I am not planning to use tick, least not in blueprints.
#2 are traces gotten with the velocity node after the on hit event.

I tried reversing the direction after On Hit, but as example B shows, it is far from accurate.
Any suggestions?

The Hit Result should have an impact velocity pin or some similar. Check that out


Those are the outputs of the event hit but unless I am completely missing something, I can’t find any direct data about the direction of the hit.

The hit event probably fires when the projectile has stopped, so you’d have to store the ‘last frame velocity’ on the projectile and use that.

‘Hit Normal’ gives you direction of the surface you’ve hit, I believe.

Im not 100% sure if this works. Try adding together Trace Start and Trace End and with the vector length node to check if it matches the projectile velocity’s length

The traces just return 0, it’s not a trace hit. The traces I’m doing in the picture are just to visualize, they are not actually used.

I think I need to do as you suggest, TheJamsh, but doing it through blueprint would destroy the projectiles performance, because they would require tick. I tried looking in visual studios but I don’t have enough knowledge of c++ to add such a variable, or where. Maybe not even how to set it.

Getting velocity every frame isn’t so heavy that itll destroy game performance unless you’re doing a ton of them at once. You can also use timers instead to get velocity at fixed timesteps so it’s not happening every frame if you need to optimize.

Cache array of flight params in Projectile Event Begin Play on a timer if Tick not used?

Depending on what you’re doing, you could make the sphere overlap with projectiles rather than collide. Then do onbeginoverlap which would allow it to retain velocity

To conclude, I decided to go with setting a ‘previous velocity’ on tick in blueprints which gives an accurate enough direction… It didn’t affect performance as much as I initially thought it would.
Thanks for the input.