- Home /
Raycast problem trough the terrain
Well, I have searched for a solution and havent found any yet. I'm using a raycast to check if the character gets grounded:
if(Physics.Raycast(transform.position+transform.TransformDirection(0,3,0),-transform.up,4))
grounded=true;
else
grounded=false;
Well, it works just fine when the character stands... When it falls it gets grounded and it wont strobe grounding and ungrounding while walking around on a terrain in different heights.
But, for some reason when I change the colliders height to half for crouching the character falls to the ground, the raycast still comes from above the terrain but it wont detect the ground anymore. ):
Crouching:
if(GetComponent<CapsuleCollider>().height!=6)
{
GetComponent<CapsuleCollider>().height=6;
}
The standings size is 12. Does anybody knows why it wont detect the ground? Or any other method to make the character crouch which would propably fix this issue?
It seems like a casual problem and yet still nobody has an answer.
I guess you should use that ins$$anonymous$$d : http://docs.unity3d.com/Documentation/ScriptReference/Terrain.SampleHeight.html
Has none to do with the problem. ): THe problem is with the grounding itself and detecting the ground while decreasing the height of the collider.. ):
Answer by benk0913 · Jun 01, 2013 at 04:39 PM
Fixed it, the raycast was starting too low, it went below the terrain when the player crouched.
Your answer
Follow this Question
Related Questions
Flattening terrain under my object at start() 1 Answer
Getting treePrototype information from RayCasting collisions onto terrain? 2 Answers
How to create a ground/terrain/floor that won't respond to gravity or objects falling on it? 1 Answer
How can I separate tree colliders from terrain colliders? 2 Answers
Raycast painted tree/terrain problem 1 Answer