- Home /
Question by
Kruhm · Sep 18, 2012 at 03:02 AM ·
raycastcharactercontrollerspherecastcapsulecollider
Inconsistent results when doing line/sphere casts?
I'm getting inconsistent cast results between CapsuleColliders and CharacterControllers. I have both in a scene and both with a height of 2 and radius of 0.5. I then run the following script on both:
void Update()
{
RaycastHit castHit;
Vector3 castStart = transform.position;
castStart.x += 100.0f;
Vector3 castDir = new Vector3( -1.0f, 0.0f, 0.0f );
float castRad = 0.5f;
float castDist = 200.0f;
if ( Physics.SphereCast( castStart, castRad, castDir, out castHit, castDist ) )
{
Debug.DrawLine( castStart, castHit.point, Color.red );
Debug.Log( "SphereCast() hit [" + castHit.collider.ToString() + "] at: " + castHit.point.ToString() );
}
if ( Physics.Raycast( castStart, castDir, out castHit, castDist ) )
{
Debug.DrawLine( castStart, castHit.point, Color.red );
Debug.Log( "Raycast() hit [" + castHit.collider.ToString() + "] at: " + castHit.point.ToString() );
}
}
The script does line and sphere casts and prints the hit position. The CapsuleCollider returns a hit position 0.5 units away, which is correct since the radius is 0.5. The CharacterController returns a hit position 0.4 units from the collider, which is inside it's radius.
Has anyone else encountered this?
Comment