Making a wall that pushes player/part to the side

I have a game where the player controls a part that goes at pretty high speeds throughout a track. The part itself has an AlignOrientation constraint inside of it to make sure it never turns the wrong direction by accident. Throughout the track there are several barriers/walls on the side, and the problem comes when the player manages to collide with said barriers.

Here is what I have (simplified):
43987d8ef5f790d0ee4591ebe8296903
Here is what I want to achieve:
43987d8ef5f790d0ee4591ebe8296903

My idea to prevent this was to cast a ray from the part when it collides with a wall, then rotate the surface normal of the ray around 90 degrees so that it points sideways and apply a force to the part in said direction, however I want to know if there is a more efficient way of solving this problem.

Any help is appreciated.

1 Like

You can cross the upvector of the barrier with the normal vector to get a vector which is perpendicular to both vectors.

That is what I had in mind, however there are several problems with this solution, mainly the fact that the result of the cross will always return right no matter what, and there would be situations where I would want the part to be pushed left instead and I have no clue on how to implement such a system

1 Like

Okay I figured it out, I did what I already thought of (getting the normal and crossing it), then got the walls CFrame in the part’s object space and applied a force in the direction of the cross multiplied by a math.sign() of the CFrame’s position Z coordinate.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.