Redirect object velocity on collision

Hi all, I’m having a problem that’s stopping me from progressing on an already ambitiously sized project. I basically want to recreate the way the rigidbody velocity is redirected when it hits a wall, since I’m building an arcade moveset and RB physics moveset, and need wall collision (and velocity redirection) to be present (and very similar) in the two modes.

Here’s an image showing the side and top view of the desired outcome.

Left being side view, right being top. The magnitude will always stay the same, just need to redirect the direction to be pretty much parallel with the collision surface.

I’ve tried getting the collision normal, then working off of that using Vector3.Cross and other things, but just cant get it to work perfectly. I’m sure it’s just a bit of math that I’m missing, but I was never a huge academic-type in the first place. :stuck_out_tongue:

Any suggestions? Anything would be super appreciated.

ProjectOnPlane might be what you’re after.

It might not keep the magnitude but just normalize the vector you get back from the function above and multiply that normalized vector with the current magnitude. I think… :slight_smile:

1 Like

Dude, I think that’s it. Seriously, nice one for that :smile:

I haven’t implemented it yet, but the function does what I need so assuming I don’t come across any other problems, I should be good to go. Thanks, man!