# Formation movement logic

Why do you need to have a bool variable at the first place?
Im more a “java” guy and stuff, Im not that fluent in C# (thats why I got this course in a first place)
But few lessons before a cool feature with directional vectors was discovered, so I was kinda confused because
I didnt spot a problem even on 7000 speed. Why is that? Because I used Vector3.left variable for the movement direction
AND for the switching the direction. Not sure if the point is clear but it’s something like this:

``````public Vector3 movementDirection = Vector3.left;

........
.......

void Update () {
if(movementDirection == Vector3.left){
this.transform.position += movementDirection * Time.deltaTime * movementSpeed;
if(this.transform.position.x <= leftBorder){
movementDirection = Vector3.right;
}
} else {
this.transform.position += movementDirection * Time.deltaTime * movementSpeed;
if(this.transform.position.x >= rightBorder){
movementDirection = Vector3.left;
}
}

float xPos = Mathf.Clamp(transform.position.x, leftBorder, rightBorder);
transform.position = new Vector2(xPos, this.transform.position.y);
}
``````

I mean - why not, right? If we have a feature that we can use - why we cant just use it instead of declaring an extra variable that will be used for the exact same thing?

1 Like