- Home /
Mesh Colliders aren't working with Physics.Raycast, but it works with the regular physics?
In short, the title says it all. Basically, what i'm trying to achieve here is a script where i can randomly spawn objects in a certain area, instead of hand-placing them. In this part of the script, down below is a raycast where it's supposed to detect the map area with a raycast, but for some reason it doesn't work! here's what i think, but i dont know how to solve the problem:
i think its because im using a mesh collider or something like that, and the mesh collider is necessary, so i can't use anything else. If you have a solution, please tell me! here's some things it's not:
its not the layermask, as i already checked that. Nor the distance, or position. It's the same as the object.
here's the things i will not do, as it'll break the purpose of the script:
turn the mesh to convex. I dunno if it'll work but its a big map and convex basically breaks the intended physics and the objects wont spawn correctly.
Here's the code down below:
float Y; RaycastHit hit; Physics.Raycast(new Vector3(X, StartY, Z), Vector3.down, out hit, 1500, 10);//the raycast if (Physics.Raycast(new Vector3(X, StartY, Z), Vector3.down, out hit, 1500, 10)) { Debug.Log("Hit"); //tells if it hit something, doesn't appear. } Y = hit.point.y; //the y position for future use Debug.Log(Y); //marks the Y position, returns 0
Edit: i figured it out, i just did RaycastAll and a foreach loop.
Your answer
Follow this Question
Related Questions
What is the cheapest way to prevent object A from going through object B 3 Answers
Using Raycasts to change the X and Y position of a moving GameObject? 1 Answer
How to check if a raycast is not hitting any tagged colliders? 0 Answers
how to stop player movemnt when there is something near him 3 Answers
onGround raycasts return onGround is true while colliding with platform sides 0 Answers