Raycast never returns 'true' when trying to detect ground terrain?

Hi,
For some reason, I cannot get ‘Physics.Raycast’ to return ‘true’ when detecting the ground collision.

Although my variable names are different, when I checked my code against the code at 10:23 in the lecture, it looks like my logic for the bool ‘isOnGround’ should work.


However, according to the print statement in the console when running the code, ‘isOnGround’ will always return ‘false.’ Obviously, since ‘isOnGround’ is false, my frog cannot jump anymore and the ‘jump action pressed’ debug statement never shows in the console.

If I hardcode ‘isOnGround’ to true, my frog can jump again.

Since the Debug.DrawRay appears to be hitting the ground (see screenshot below), I thought I might have some issue with my frog or terrain collider, however my frog’s rigid body appears to match the lecture at time 11:56. I tried switching the ‘collision detection’ drop down to ‘continuous’ and ‘continuous dynamic’ to see if it made a difference, but it didn’t so I put it back to ‘discrete’.

My Terrain collider matches what is shown in the lecture at time stamp 9:46… I tried adding another ‘mesh collider’ to the terrain, but then I removed it again when it didn’t help.

I am using Unity Version 5.4.5f1

Version 5.4.5f1 (68943b6c8c42) Personal
Mon, 06 Mar 2017 22:00:54 GMT
Branch: 5.4/release

Originally I was using 5.4.1, but I upgraded to 5.4.5 when I ran into this ray cast issue. (Early in the class I installed 5.4.1 to different folder because the APIs wouldn’t work with some of the lectures when I was using 5.6)

I am out of ideas on how to continue debugging, and didn’t really find any additional useful info on the web (ray cast seems like it should have worked with terrain collider).

Any ideas?

Thanks for the help…!
Isabelle

Okay- so my colliders were fine, but my friend pointed out that my terrain had ‘layer’ set to ‘ignore raycast’…
Changing the dropdown to ‘default’ fixed the jump issue…

Hopefully this saves someone else a few hours of debug time… (>.<)

Privacy & Terms