Home > OS >  Draw only rectangle's angles c# unity
Draw only rectangle's angles c# unity

Time:08-10

I am trying to make a harmeless esp for Ghost Watcher (a new ghost game). However I have a question: how could I render the esp box such as only the angles are rendered? so, instead of a full rectangle only four angles are shown? The idea was to change the points used to draw the lines of the box.

The model is: image The code result in:

public static void DrawBox(float x, float y, float w, float h, Color color, float thickness)
{
  Vector2 P1 = new Vector2(x, y);
  Vector2 P2 = new Vector2(((x w)/2)-10, y);
  Vector2 P3 = new Vector2(((x w)/2) 10, y);
  Vector2 P4 = new Vector2(x w, y);
  Vector2 P5 = new Vector2(x, ((y h)/2)-20);
  Vector2 P6 = new Vector2(x, ((y h)/2) 20);
  Vector2 P7 = new Vector2(x, y h);
  Vector2 P8 = new Vector2(((x w)/2)-10, y h);
  Vector2 P9 = new Vector2(((x w)/2) 10, y h);
  Vector2 P10 = new Vector2(x w, y h);
  Vector2 P11 = new Vector2(x w, ((y h)/2) 20);
  Vector2 P12 = new Vector2(x w, ((y h)/2) 20);
  DrawLine(P1, P2, color, thickness);
  DrawLine(P1, P5, color, thickness);
  DrawLine(P3, P4, color, thickness);
  DrawLine(P4, P12, color, thickness);
  DrawLine(P6, P7, color, thickness);
  DrawLine(P7, P8, color, thickness);
  DrawLine(P9, P10, color, thickness);
  DrawLine(P10, P11, color, thickness);
}

Which is called as:

float height = headpos.y - footpos.y;
float widthOffset = 2f;
float width = height / widthOffset;
string entity = "Ghost";
//ESP BOX on the ghost
Render.DrawBox(footpos.x - (width / 2), (float)Screen.height - footpos.y - height, width, height, color, 2f, entity);

However it seems not to be working.

The result is: image So, do u guys have any idea of the reason, or do u have a solution?

CodePudding user response:

The problem is in your math for finding the midpoints of the lines.

(x w)/2 is incorrect (this is the average between X and width), you should instead use x (w/2). Likewise with Y.

Also, your line for P12 is 20, instead of -20.

public static void DrawBox(float x, float y, float w, float h, Color color, float thickness)
{
  Vector2 P1 = new Vector2(x, y);
  Vector2 P2 = new Vector2((x (w/2))-10, y);
  Vector2 P3 = new Vector2((x (w/2)) 10, y);
  Vector2 P4 = new Vector2(x w, y);
  Vector2 P5 = new Vector2(x, (y (h/2))-20);
  Vector2 P6 = new Vector2(x, (y (h/2)) 20);
  Vector2 P7 = new Vector2(x, y h);
  Vector2 P8 = new Vector2((x (w/2))-10, y h);
  Vector2 P9 = new Vector2((x (w/2)) 10, y h);
  Vector2 P10 = new Vector2(x w, y h);
  Vector2 P11 = new Vector2(x w, (y (h/2)) 20); 
  Vector2 P12 = new Vector2(x w, (y (h/2))-20);   //was incorrectly set to  20
  DrawLine(P1, P2, color, thickness);
  DrawLine(P1, P5, color, thickness);
  DrawLine(P3, P4, color, thickness);
  DrawLine(P4, P12, color, thickness);
  DrawLine(P6, P7, color, thickness);
  DrawLine(P7, P8, color, thickness);
  DrawLine(P9, P10, color, thickness);
  DrawLine(P10, P11, color, thickness);
}
  • Related