I’m trying to make a 3rd person camera that will move up towards the character instead of going through walls. The code I have works pretty well, except for one thing. I have invisible cubes around the tutorial area that I use to display GUIs when you walk inside them. The problem is that the camera will detect the invisible cubes and move when it shouldn’t. The camera code is here:
using UnityEngine; using System.Collections; public class CameraCollision : MonoBehaviour { public float minDistance = 10.0f; public float maxDistance = 4.0f; public float smooth = 10.0f; Vector3 line; float distance; void Awake() { line = transform.localPosition.normalized; distance = transform.localPosition.magnitude; } void Update() { Vector3 desiredCameraPos = transform.parent.TransformPoint(line * maxDistance ); RaycastHit hit; if( Physics.Linecast( transform.parent.position, desiredCameraPos, out hit ) ) { distance = Mathf.Clamp( hit.distance, minDistance, maxDistance ); } else { distance=maxDistance; } transform.localPosition=Vector3.Lerp(transform.localPosition, line * distance, Time.deltaTime * smooth); } ` The cubes have no scripts, the GUI is on the character, but they do have a box collider set as a trigger. `