Raycast in 2D Game?

So I’ve been trying to tackle this issue for months now…

I have a ship I want to spawn on the seafloor. The seafloor sprite has slopes. I want the ship to land on the seafloor and align itself properly with the slope of the seafloor. Trick is to do this without gravity or preset positions. Any way I can do this?

The way I’ve done it is to apply gravity and have gravity do the job. The problem with this is when I speed up the fish, the ship can be seen tilting itself to align with the seafloor. I do not want that to be seen. I want the ship to always be aligned by the time it is visible on screen.

The other way I’ve done it was to have a few preset positions for the ship to spawn at (with preset Y position and Z rotation). The problem with this however is (a) the seafloor moves over time as it teleports periodically, which cancels out the benefit of having preset positions, and (b) it’s not as random as I would like it to be.

Is there ANY way to just have the ship know how to align itself with the slope of the seafloor without using gravity?

I’ve read some on Raycast and was suggested to use it, but I can’t seem to get it to work in my 2D game. Am a Raycast noob. :frowning:

Any help would be greatly appreciated!!

- Chris

We don’t know how you used the Raycast, how’d you do it?

First off, make sure you’re using the 2d raycasting, and not the 3d, since your game is 2d:

But after that, how do you use it? Is it similar to the example in that link?

I tried that exact thing and it doesn’t work. Unless I’m just not using it right? I have rigidbody2D attached and assigned and the script is exactly how it is in the reference. Gravity set and all that. As far as I can tell, the script changes nothing. It still drops solely using gravity.

Is there anything else that needs to be done?