# Planet Movement - Glitches and Collision Problem

Hi there,

I’ve figured out a script how to do movement on uneven terrains, like a round planet.

It works like this:

1. The transform is moved and y-rotated in the desired direction
2. A ray is casted from the object in its -vector3.up direction (negative y-axis)
3. If the ray hits the surface, the object is moved there
4. The object’s up vector becomes the normal of the ray collision point ( = it stands with the feet on the ground)

Here are the problems:

• When the object moves, it glitches all way long. That means it tilts around it’s z axis very fast, 5° left, 5° right
• When the object moves from the “north pole” to the “south pole”, it rotates itself endlessly around it’s y axis on the south pole

I think I know the first problem’s reason: The planet, as every 3D-Object, isn’t perfectly round. If the Object moves along the edge of two polygons, the ray hits both polys and as the polys are flat and have got a different angle, the object is set to both angles simultaneously (Step 4 of my script), which causes glitches.

I thought I’ve found a solution: Enabling “smooth sphere collisions”. I thought it smoothes the poly-normals so it imitates a rounder shaped surface. This should solve the first problem. HOWEVER, it DOESN’T.

Further, I don’t know where the second problem comes from, but if I use a Sphere Collider for my Planet, instead of the mesh one, everything works. Unfortunately, my planet has some valleys and hills, so a sphere collider doesn’t work as the object would move above the valleys and through the hills.

So finally, here are my two questions:

1. Why does this smooth sphere collision thing not work? Did I do something wrong or is it generally not suited for my problem?
2. Why does the object do these strange infinite rotations around itself if I use the mesh collider?

Thank you so much!

Instead of moving the object’s position, have it lerp towards the most recent target position over a short period of time.

You didn’t give any information on how you’ve moving and rotating the object, but if I had to guess you’re modifying the Euler angles directly and causing gimbal lock. Search the forums and the web and tons of info will pop up.

tl/dr solution is to rotate x/y and z in separate steps.