# 2d Raycasting on rotating rectangle.

I was doing my collisions via Raycasting from a collider horizontally and vertically base on collider bounds, problem is when rotating the collider, I want the rays to be perpendicular on the collider rectangle itself not on its bounds. Any idea how to do it properly?

More details:

I was following tutorials from youtube by

``````   public void UpdateRaycastOrigins()
{
Bounds bounds = collider2d.bounds;
bounds.Expand(skinWidth * -2);

raycastOrigins.bottomleft = new Vector2(bounds.min.x, bounds.min.y);
raycastOrigins.bottomRight = new Vector2(bounds.max.x, bounds.min.y);
raycastOrigins.topleft = new Vector2(bounds.min.x, bounds.max.y);
raycastOrigins.topright = new Vector2(bounds.max.x, bounds.max.y);
}

void CalculateRaySpacing()
{
Bounds bounds = collider2d.bounds;
bounds.Expand(skinWidth * -2);

float boundsWidth = bounds.size.x;
float boundsHeight = bounds.size.y;

horizontalRayCount = Mathf.RoundToInt(boundsHeight / dstBetweenRays);
verticalRayCount = Mathf.RoundToInt(boundsWidth / dstBetweenRays);

horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);

}
``````