I’m trying to make the camera move to the character on click on the icon. I came up with two ways.
public GameObject hhh;
bool IsTargetVisibleV1(GameObject go)
{
var planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
var point = go.transform.position;
foreach (var plane in planes)
{
if (plane.GetDistanceToPoint(point) < 0)
return false;
}
return true;
}
bool mm = false;
public void vidvid()
{
if (IsTargetVisibleV1(hhh) == true)
{
mm = false;
}
else
{
mm = true;
}
}
private void Update()
{
if (mm == true)
{
if (
Vector3.Distance(Camera.main.transform.position, new Vector3(gameObject.transform.position.x - 58, 80, gameObject.transform.position.z - 58)) > 0.5
)
{
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, new Vector3(gameObject.transform.position.x - 58, 80, gameObject.transform.position.z - 58), Time.deltaTime * 2);
if (Input.anyKey == true) mm = false;
}
else
{
mm = false;
}
}
}
Another variant.
public GameObject hhh;
bool IsTargetVisibleV1(GameObject go)
{
var planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
var point = go.transform.position;
foreach (var plane in planes)
{
if (plane.GetDistanceToPoint(point) < 0)
return false;
}
return true;
}
public void vidvid()
{
if (IsTargetVisibleV1(hhh) ==false)
{
Camera.main.transform.position = new Vector3(gameObject.transform.position.x - 58, 80, gameObject.transform.position.z - 58);
}
}
The first option is not accurate, and the second option is a teleport.I know what else can be done through “Translate”. But I didn’t succeed. Please tell me how to do it.