# Circlecast Radius Seemingly Smaller Than I’ve Set It

Hello!

I’ve been having an issue with `CircleCastAll(...)` and I’m just not sure what I’m doing wrong.

Essentially, I’m wanting to allow a bullet object, which has a `CircleCollider2D` set as a trigger, to bounce off of a wall when it hits it.

My code for this method, with some added commented info, is as follows:

``````// lastPos is set equal to transform.position in LateUpdate()
// rb is the bullet's RigidBody2D
// cc is the bullet's CircleColider2D
// Bounce(...) is called in OnTriggerEnter2D(...) and OnTriggerStay2D(...), depending on the collider
void Bounce(Collider2D surface) {
RaycastHit2D[] obstacles = Physics2D.CircleCastAll(lastPos, cc.bounds.extents.x, rb.velocity);

foreach (RaycastHit2D hit in obstacles) {
if (hit.collider == surface) {
// Debugging
Debug.DrawLine(hit.point, hit.centroid);
Debug.DrawLine(lastPos, hit.centroid, Color.red);
print(Vector2.Distance(hit.point, hit.centroid) + "; should be " + cc.bounds.extents.x);

// Performing the bounce
transform.position = hit.centroid + hit.normal * 0.01f;
rb.velocity = Vector2.Reflect(rb.velocity, hit.normal);

break;
}
}
}
``````

To simplify, this method calls `CircleCastAll(...)` from the bullet’s position in the previous frame, with a radius of its collider and a direction of its velocity. It then iterates through the list of hits until it finds the wall causing the trigger event. Then the three lines under “Performing the bounce” bounce the bullet by setting the bullet’s position to just off of the centroid, in the direction away from the wall (this is to avoid hitting the same point twice in the case of two successive bounces), reflecting the bullet’s velocity over the surface normal, and setting its rotation to reflect the new direction it is heading.

It seemed to work perfectly until I started testing it with nearly flat angles. What happens is the bullet teleports forward when it hits the wall. Here is an extreme example of this happening with a very flat angle (note that the line of code that sets the bullet’s position while bouncing has been commented out in this example, to show where it actually hits the wall):

The bullet is the selected black square with the yellow dash. The white line is created with the first line under “Debugging” and shows the vector between the hit point and the centroid. The red line is created with the next line and shows the vector between the bullet’s last position and the centroid. It appears that the circlecast is hitting the wall much farther along the bullet’s trajectory than the bullet itself is. The only explanation I can come up with for this is that the radius of the circlecast is smaller than the radius of the bullet’s collider. This is what I wrote the third line under “Debugging” for. It prints the distance between the hit point and the centroid (which I believe should be equal to the radius of the circlecast, but please correct me if I am misunderstanding this) followed by the radius of the bullet’s collider.

The results are as follows:

Assuming I’m not misunderstanding things, this seems to prove me correct. The radius I have set for the bullet’s collider is `0.125`, which prints correctly every time. The first number, however, is always less. What confuses me is that it is always very close (around `0.1175`, with `0.1175003` showing significantly more often than any other result), but still differs. This goes for all bounces, even at non-flat angles. It’s just less noticeable since the circlecast doesn’t travel as far when it’s moving directly toward the wall.

This is as far as I’ve managed to get in figuring out this issue. Is my circlecast radius smaller than I’m setting it?

Is this just some weird float rounding issue I haven’t learned to avoid yet?

Or is it something else?

Any help would be much appreciated. Thanks!