My camera wont stay above the ground I have in my scene. How to fix?
My camera is a child of an object that rotates. The object it placed at a point above ground and the rotation is controlled by the mouse dragging across the screen. The ground is a plane I believe. I want the camera to just not go below the ground. I have added colliders to the camera itself. Any tips or suggestions of what I could do would be nice.
Answer by frilanski · Jun 04, 2021 at 09:24 PM
Assuming you're trying to get the camera to follow the object:
Personally, I would remove the camera from being a child object so that its translation isn't relative to the rotating object.
Then, make a script that performs the following actions every fixed update:
Gets the position of the rotating object.
Calculate the position you want the camera to be in using the objects world position.
Then, either just set the cameras position to the calculated position. Or, if you're feeling fancy, you can use Lerp to make the camera 'soft follow' the object by only moving a fraction of the distance towards it's desired location each update. Have done this, looks real professional for such a small script.
Your answer
Follow this Question
Related Questions
Limit game object to camera view 0 Answers
Collision in the air after jumping 1 Answer
Player respawn after collision 0 Answers
Focus Camera on object to use GUI Interface. 0 Answers
How do you stop SteamVR Player from colliding with a car? 0 Answers