Raycast problem, likely a Unity bug?
I have a character using CharacterController. I use a capsule collider to do damage detection. Every character has a different capsule collider radius, I adjust the radius in script on initialization. I find Physics.Raycast returns wrong result as shown in the following picture.
My Character stands on a BoxCollider ground. The Raycast hitInfo returns correct hit point as shown in the pic, but returns capsule collider as hit collider.
Show us your code. With all due respect, most of the "Oh, Unity has a bug" is actually due to user program$$anonymous$$g errors.
RaycastHit hitInfo;
if (distance > 0 && Physics.Raycast(startTrace, direction, out hitInfo, distance, layer$$anonymous$$ask))
{
if (hitInfo.collider != null)
{
impactInfo = ImpactInfo.Alloc();
impactInfo.HitCollider = hitInfo.collider;
impactInfo.HitObject = hitInfo.collider.gameObject;
impactInfo.HitLocation = hitInfo.point;
impactInfo.HitNormal = hitInfo.normal;
impactInfo.RayDir = direction;
impactInfo.StartPosition = startTrace;
impactInfo.ActorLayer = impactInfo.HitObject.layer;
impactInfo.Distance = hitInfo.distance;
impactInfo.HitGroup = EHitGroup.Default;
impactInfo.HitPhysic$$anonymous$$aterial = hitInfo.collider.material;
return true;
}
return false;
}
Code is simple. I will try to reproduce it in a simple project.
Your answer
![](https://koobas.hobune.stream/wayback/20220612065420im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Physics.Raycast is not working with VR 0 Answers
RaycastHit The best overloaded method has some invalid arguments 0 Answers
Change Scene with Physics Raycasting 1 Answer
Physics.BoxCast not returning a hit when scale too small 0 Answers
Gun RayCast Origin lags with fast moving object. Help? 0 Answers