I have a strange problem with the setBox function below. Basically, when the player clicks on a unit in my game, the setBox function determines the 4 corners of the entity, and the drawRectCorners function draws lines at these 4 points to highlight the unit.
However, the highlighting seems to be much bigger than the entity. You can see what I mean below:

Now here is the strange thing - if I replace the 3d models with cubes (using createCube), it works pefectly which indicates that the code is correct and maybe it is the models that are the problem (but the models seem fine to me).
Any help would be most appreciated.
However, the highlighting seems to be much bigger than the entity. You can see what I mean below:

Now here is the strange thing - if I replace the 3d models with cubes (using createCube), it works pefectly which indicates that the code is correct and maybe it is the models that are the problem (but the models seem fine to me).
Any help would be most appreciated.
Function setBox(obj) ;calculate corners (screen coords) of entity map\boxW# = MeshWidth(obj) map\boxH# = MeshHeight(obj) depth# = MeshDepth(obj) width2# = map\boxW# / 2 height2# = map\boxH# / 2 depth2# = depth# / 2 CenterX# = EntityX(obj) CenterY# = EntityY(obj) CenterZ# = EntityZ(obj) map\boxX# = scrnWidth map\boxY# = scrnHeight x2# = 0 y2# = 0 TFormVector -width2#, +height2#, +depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(0,0) = ProjectedX() Points(0,1) = ProjectedY() TFormVector +width2#, +height2#, +depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(1,0) = ProjectedX() Points(1,1) = ProjectedY() TFormVector -width2#, +height2#, -depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(2,0) = ProjectedX() Points(2,1) = ProjectedY() TFormVector +width2#, +height2#, -depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(3,0) = ProjectedX() Points(3,1) = ProjectedY() TFormVector -width2#, -height2#, +depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(4,0) = ProjectedX() Points(4,1) = ProjectedY() TFormVector +width2#, -height2#, +depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(5,0) = ProjectedX() Points(5,1) = ProjectedY() TFormVector -width2#, -height2#, -depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(6,0) = ProjectedX() Points(6,1) = ProjectedY() TFormVector +width2#, -height2#, -depth2#, obj, 0 CameraProject cam\camera, CenterX#+TFormedX#(), CenterY#+TFormedY#(), CenterZ#+TFormedZ#() Points(7,0) = ProjectedX() Points(7,1) = ProjectedY() ;set box coords & size For n = 0 To 7 If Points(n,0) < map\boxX# Then map\boxX# = Points(n,0) If Points(n,1) < map\boxY# Then map\boxY# = Points(n,1) If Points(n,0) > x2# Then x2# = Points(n,0) If Points(n,1) > y2# Then y2# = Points(n,1) Next ;calculate width & height of box map\boxW# = x2# - map\boxX# map\boxH# = y2# - map\boxY# ;add offset of camera view map\boxX# = map\boxX# + cam\viewX map\boxY# = map\boxY# + cam\viewY End Function Function drawRectCorners(x, y, w, h, size = 10, lw = 2) ;draws corners of a rectangle xw = x + w yh = y + h ;top left corner Rect x, y, size, lw, True Rect x, y, lw, size, True ;top right corner Rect xw - size + lw, y, size, lw, True Rect xw, y, lw, size, True ;bot right corner Rect xw - size + lw, yh, size, lw, True Rect xw, yh - size + lw, lw, size, True ;bot left corner Rect x, yh, size, lw, True Rect x, yh - size + lw, lw, size, True End Function