Drag And Drop Sliding around a box in top down shooter

I am making a space shooter with indoor rooms, and when my ship collides with a surface, I want it to slide either up or down or left or right on the object, depending on if the surface is horizontal or vertical.

In this video, you can see that I have figured out how to get the ship to slide properly on vertical surfaces of the box, but not on horizontal. When the ship collides with the box on the top or bottom horizontal surfaces, it just gets stuck. This is odd, because I used the same DnD code as the vertical sliding and tried to just modify it for horizontal sliding. But obviously it does not work.

My DnD code screenshot is attached. What am I doing wrong?

 

Attachments

Last edited:
Top