0
\$\begingroup\$

A quick introduction to my problem at the moment: I am currently having trouble with checking whether or not a cylinder is grounded. I am using a mesh collider (octagonal prism) as my main collider for the object, however I can't seem to get a reliable ground detection beneath it. I have tried using a trigger and raycasting, but neither seem to work correctly.

It would be a great help if you could either provide a method of correctly raycasting the cylinders base, or an alternate method (bearing in mind the object rotates on all axis). Many thanks in advance. (terrible diagram below)

terrible diagram

\$\endgroup\$
2
  • \$\begingroup\$ "neither seem to work correctly" is pretty vague. You might not get the answers you need unless you tell us specifically what's wrong. The answers provided might pose the same problems you already have, since we don't know what those problems are. \$\endgroup\$
    – House
    Jul 29, 2016 at 17:38
  • \$\begingroup\$ you can use shapes Raycasting : Physics.SphereCast , Physics.CapsuleCast, Physics.BoxCast , Collider.Raycast \$\endgroup\$ Jul 29, 2016 at 17:39

1 Answer 1

1
\$\begingroup\$

Use a RigidBody SweepTest.

If your cylinder is not already a rigid body, make a duplicate of it for this test. Utilizing the rigidbody component on your object, call the sweep test to detect if moving the body down a very small amount hits ground.

It's essentially a raycast for each point in the rigidbody, as described in the description:

Tests if a rigidbody would collide with anything, if it was moved through the scene. This is similar to doing a Physics.Raycast for all points contained in any of a Rigidbody's colliders and returning the closest of all hits (if any) reported.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .