# Basic vector math addition

**URL:** https://discussions.unity.com/t/basic-vector-math-addition/19544
**Category:** Questions & Answers
**Created:** [April 22, 2011, 8:12pm UTC](https://discussions.unity.com/t/basic-vector-math-addition/19544 "2011-04-22T20:12:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [April 22, 2011, 8:12pm UTC](https://discussions.unity.com/t/basic-vector-math-addition/19544/1 "2011-04-22T20:12:00Z")

</div>

I feel like I should know this because we went over it in calculus 3 but Im having hardest time getting my vector math to work.

Basically I need to draw a box in the editor based off of this information

```auto
public int boundaryLength = 10;

public int boundaryWidth = 10;

public GameObject boundaryStart; // where to start drawing from

```

I then try to draw the box with the following code

```auto
void OnDrawGizmos ()
{   
    //draw a greenbox around the boundary area
    if(visualizeGrid == true)
    {
        //draw a a green boundary box
        Vector3 point_1 = boundaryStart.transform.position;
        Vector3 point_2 = new Vector3(boundaryStart.transform.position.x + boundaryLength,0,0);
        Vector3 point_3 = new Vector3(boundaryStart.transform.position.x + boundaryLength, 0, boundaryStart.transform.position.z + boundaryWidth);
        Vector3 point_4 = new Vector3(0, 0, boundaryStart.transform.position.z + boundaryWidth);   

        Gizmos.color = Color.green;
        Gizmos.DrawLine(point_1, point_2);
        Gizmos.DrawLine(point_2, point_3);
        Gizmos.DrawLine(point_3, point_4);
        Gizmos.DrawLine(point_4, point_1);      
    }
    else
    {
        return; //if visualize gride is turned of, exit function    
    }
}

```

This to me seems like it should draw, but I get this weird quadrilateral that is a half box half...not box

Maby my math is wrong but i cant seem to see where

---

<div class="post-metadata">

### Author: ![DaveA](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@DaveA](https://discussions.unity.com/u/DaveA)
#### Post date: [April 22, 2011, 8:20pm UTC](https://discussions.unity.com/t/basic-vector-math-addition/19544/2 "2011-04-22T20:20:18Z")

</div>

Vector3 point\_4 = new Vector3(0, 0, boundaryStart.transform.position.z + boundaryWidth);

Your x,y for this is always zero. transform.position is in world coords. I think you want some thing more like:

Vector3 point\_4 = new Vector3(boundaryStart.transform.position.x, 0, boundaryStart.transform.position.z + boundaryWidth);

In other words, your 'local origin' will be transform.position.x and z, and the offsets will be position.x + length and .z + width.
