How to make a raycast detect a trigger that its above of an object with mesh collider?
I'm aiming to create a camera movement limitador on the borders of my scenario, don't know if there's a better way to achieve this, but I was thinking about using triggers and a raycast to detect the position of the mouse on the borders, once the raycast hits the trigger, the camera movement must stop. It happens that raycast is not detecting the collision with these triggers. Not sure if this is happening because of these triggers are above of the plane (with mesh collider) that I'm using as scenario.
After some googling, I found some answers about raycasts and triggers, then the collider's property "isTrigger" was mentioned, but it's not working either. My code is something like this:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
if(hit.collider.isTrigger)
{
//When the mouse is hovering the trigger this isn't being called
}
Answer by gabrimo · Sep 29, 2018 at 02:01 AM
A friend of mine helped me to realize that my choice was wrong. I'm creating a code that will set an map size property (with map's maxX,minX, maxZ and minZ). After that, some conditions with the mathf.clamp should do the trick from what Ive heard...
Your answer
![](https://koobas.hobune.stream/wayback/20220612175307im_/https://answers.unity.com/themes/thub/images/avi.jpg)