How to move an object on a terrain that will always stay on top of the terrain?

Hey guys!

Im kinda new to Unity, but here i go.
Im making a Strategy game with upper view, and i have a fix terrain where the game will be played.
I would like to move a sphere object on the terrain like a ball, but i dont want this sphere affected by physics law, so basically i want my sphere to collide with the terrain collider, but when i stop moving this ball, it should stay where i stopped moving, for example on a 75 degree slope.
So basically i want a ball rolling on the terrain without phsysics.(always sticking to the terrain)
How should i do this?
Write a collider script or im missing a built in function? - any tips are appreciated! :slight_smile:

2 Answers

2

Is it Terrain.SampleHeight(position) you’re looking for? Maybe move the ball around x and z, but set its y position on the terrain with SampleHeight every frame that it is moved.

i think this is what im looking for thank you ^^, if im suceed ill accept your asnwer :)

How to use it for future folks!:
Vector3 CurrentPos = Camera_Sphere.transform.position;
CurrentPos.y = Terrain.activeTerrain.SampleHeight(Camera_Sphere.transform.position);
Camera_Sphere.transform.position = CurrentPos;

(I had a Main_camera and a sphere the camera was a child of the Camera_Sphere object)