I was trying to do it like this: (As others have suggested.)
It works for the most part, but it’s not perfect. For example: If I’m playing with a low frame rate, and I hit a ceiling immediately after jumping, the Z velocity value returns zero!
It seems that the recorded velocity isn’t actually the velocity before impact, but rather it’s the velocity the player had on the previous frame before the collision occurred on the next frame. Playing with a faster frame rate will increase the accuracy of the recording, but I’m pretty sure it still isn’t perfect. This could cause various bugs if the frame rate does not stay consistent.
Is there any way to get a perfectly accurate recorded velocity?
having the exact same issue here. I got around it by making a thin invisible collider above my platform, but the collider is quite buggy and often doesn’t record the overlap, even with CCD turned on.
I assume that the red capsule is “CapsuleComponent”, if yes, then a possible solution would be to add a slightly bigger capsule that will be used as a pre-overlap check for the velocity before hitting something. You will probably tweak how much bigger it is than your character capsule to get the best results for what you need.
To the original question - have you got ‘simulate physics’ ticked for both the character and the object?
And then use a get velocity on hit after that?
That fixed mine - well - it didn’t fix because I’m using sprites and 2d and so adding ‘simulate physics’ actually messed up a whole load of other things, but in 3D games that could be the solution.
I also tried adding a capsule component like you said, buuuuut if my character is moving really fast (he does), it is still buggy and often reads the speed as 0.
(Yes, that is a “character capsule component” that I’m using.) I’m afraid I had no luck getting your solutions to work for me. Unless I did something wrong, adding another capsule to check for overlaps seemed to return the exact same velocity as my previous method.
Setting the actors to simulate physics messed up the character movement component, and since I’m not sure how to fix that, I was unable to properly test collisions
Thank you so much anyways! If you think I did something wrong let me know. I will be happy to answer any questions.