Hello, I was wondering if there was a way to move the camera distance down if the camera touches the terrain. So that you can’t see through the terrain. I was thinking OnCollisionEnter, but I don’t know how to implement it. I know how to access the smooth follow script and change the distance, I just need to know how I tell Unity that the camera touched and object and needs to be moved. Thanks in advance for any help. ![]()
1 Answer
1I would just put a sphere collider on it and use OnTriggerEnter, and check the collided objects tag for terrain or loop through an array of tags. You could also try Physics.OverlapSphere to see all objects within a radius, and loop through the given array to check for terrain.
Ok, I will try OnTriggerEnter. :)
– BincredibleI used OnTriggerEnter, this is my script: #pragma strict function OnTriggerEnter(other : Collider){ if(other.tag == "Cube"){ var m : MySmoothFollow = GetComponent(MySmoothFollow); m.distance = 1; } } function OnTriggerExit(){ var i : MySmoothFollow = GetComponent(MySmoothFollow); i.distance = 14; } This method doesn't work, am I doing something wrong? Thanks!
– BincredibleSorry for the late reply, but by default the terrain collider probably isn't set as a trigger, I don't think triggers can collide with anything. You should raycast downward and get the distance to the terrain, if it is too low then adjust the camera height how you like.
– Josh707