Collision detection with CapsuleCast

Hi,

I’m attempting to detect when a gameObject with a Capsule Collider and RigidBody attached it lands on the floor, which is a Mesh with a Mesh Collider attached it to it. Adding a tag to the Floor causes collision issues as other materials comprise the Mesh. The Physics.CapsuleCast seems like the best route, but I’m sure how the call should be made?

Help is appreciated.

Because of how the 3D casting methods work a capsule cast will fail to detect anything if your character is already touching the ground. A better method is to use a SphereCast:

if (Physics.SphereCast(transform.position,0.5f,-transform.up,out RaycastHit hit,0.51f))
{
    Debug.Log("We're standing on something!");
}

Hi zulo3d,

Thanks for the response. It’s appreciated. Actually, the game object is a Cylinder not a character. A character is tossing the cylinder onto the floor. I probably should have stated this in the initial post. My apologies.

You can detect when the capsule hits the floor with this:

	void Start()
	{
		rb=GetComponent<Rigidbody>();
	}

	void FixedUpdate()
	{
		if (rb.velocity.y<0 && rb.SweepTest(Vector3.down, out RaycastHit hit, -rb.velocity.y*Time.deltaTime))
			Debug.Log("We just landed");
	}

Hey zulo3d,

Thanks for the suggestion but unfortunately, the If condition or SweepTest in FixedUpdate isn’t met.