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! :)
Answer by JavaMcGee · Jun 11, 2017 at 06:56 PM
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 :)
Answer by Menyus777 · Jun 11, 2017 at 09:48 PM
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)
Your answer
Follow this Question
Related Questions
Why is my trigger collider acting like a normal collider? 1 Answer
How To how ?? 2 Answers
Ignore collision based on position 1 Answer
How to pick up an object in hand e.g. a bat C# 0 Answers
Need help with making a burger mechanic. 0 Answers