- Home /
Raycasting doesn't hit terrains
Hi, I've been trying to solve this problem for quite some time now but I'm yet to find a solution.
My game has a dude with a gun which shoots with a raycast but I can't seem to make it collide with the terrain.
First off I tried the regular old "Physics.Raycast" which hit the instances in the scene properly but didn't hit the terrain object. Then I created a "public TerrainCollider terrain" and used "terrain.Raycast" for it instead. I didn't get any errors but the ray still wouldn't collide with the terrainCollider.
The terrain was attached to the script. But I realized when I hit play it only showed "None (TerrainCollider)" in the editor instead of the terrains name. So I paused the scene in play mode and reattaced the terrain to the clone of the bullet prefab, and then it collided.
Is there any way to keep the terrainCollider attached to a script during play mode? Or is there a better way to handle raycast collisions with the terrain?
If you want the code or some screenshots for further information so you can help me solve this problem then just ask.
Thanks in advance ;)
Your answer
Follow this Question
Related Questions
How often do Raycasts check for collisions? 1 Answer
Get Terrain location at raycast point 1 Answer
Is there a problem with my raycast? 1 Answer
Raycasting from object rotation? 1 Answer
Problem with raycast detection? 1 Answer