Hello there,
Why we use * 0.5 in
float rightEdgeOfFormation = this.transform.position.x + (0.5f * width);
float leftEdgeOfFormation = this.transform.position.x - (0.5f * width);
Why 0.5f ?
Thanks
Hello there,
Why we use * 0.5 in
float rightEdgeOfFormation = this.transform.position.x + (0.5f * width);
float leftEdgeOfFormation = this.transform.position.x - (0.5f * width);
Why 0.5f ?
Thanks
There are two reasons.
Say the width of the object is 500 pixels and the current transform.position.x is at 600 pixels.
If you divide the width by half you get 250 pixels. This is the center of the x plane of that object. Now if you add that number to the current transform.position.x , You get 850 pixels. That it the current position of the right most edge of the object. If you do the same but subtract you get 350 pixels. That is the left most edge.
Assuming transform.position.x is currently at 600 pixels and the width of the object you are manipulating is 500 pixels wide.
Right Edge = transform.position.x + (0.5f * width)
850 = 600 + (0.5f * 500)
850 = 600 + 250
Left Edge = transform.position.x - (0.5f * width)
350 = 600 - (0.5f * 500)
350 = 600 - 250