Moving an object away from collider

Hi all

I have a game with a character that moves pretty fast.

It works more or less like this: When I indicate a direction with arrow keys, the player casts a ray in that direction and then lerps towards the point where the ray hit an object that I have tagged as “wall”.

Because of the player’s very high speed, he’ll often be clipping slightly into the wall once I get to setting my movement variable to false.

I want to have the player detect if they keep colliding with the object (OnCollisionStay, I assume) and then finding the shortest path out and place the player just outside of the collider.

Any ideas how to go about doing this?

You may want to try storing the object’s position every frame there is not a collision and, if there is a collision, you use that last position, cast a ray from that last position to the current position, and place the object on the surface of the first point that the ray hits. You may also want to correct the velocity using a plane mirror equation against the triangle the ray hits so that it does not keep going through the collider and getting stuck there.