Hi
I am using a trigger collider to check if my camera is colliding with any objects and I want to then have it move around the object.
I am using a modified version of the MouseOrbit script. I have tried to use OnCollision to get the extra info but it just sends my camera into a crazy spin.
Here is what I have so far:
void OnTriggerEnter(Collider other)
{
RaycastHit hit;
float offset = 0.5f;
Vector3 collDirection = other.transform.position - transform.position;
float collDistance = Vector3.Distance(transform.position, other.transform.position);
Debug.DrawRay(transform.position, collDirection, Color.yellow);
if(Physics.Raycast(transform.position, collDirection, out hit, 1))
{
Debug.Log(hit.distance);
if(hit.distance < offset)
{
Debug.Log("Collision - Direction: " + collDirection + " - Distance: " + collDistance);
desiredDistance = Mathf.Lerp(currentDistance, hit.distance + 0.1f, 1);
}
}
}
The problem is that it never registers the RaycastHit although sometimes it randomly comes up.
If someone could give me a hand with this or maybe even a different more efficient way then I would be very grateful, thankyou.