Player movement stops working after hitting a boundary

I checked with a debug.log and it still runs the line of code for movement, but something is restricting the movement after I collide with a boundary.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
   
    private Collider[] Boundary;

    void Start ()
    {
        GameObject[] walls = GameObject.FindGameObjectsWithTag("Boundary");

        Boundary = new Collider[walls.Length];

        for (int i = 0; i < Boundary.Length; i++)
        {
            Boundary[i] = walls[i].GetComponent<Collider>();
        }
    }
   
    void Update ()
    {
        movement();
    }

    void movement ()
    {
        Vector3 CarPosition = new Vector3(0, 0, 0);


        //Car controls
        Vector3 translation = new Vector3(0, 0);
        if (Input.GetKey(KeyCode.W))
        {
            CarPosition = new Vector3(0, 250) * Time.deltaTime; //Y axis altered by 250 over time
        }
        if (Input.GetKey(KeyCode.S))
        {
            CarPosition = new Vector3(0, -250) * Time.deltaTime; //Y axis altered by 250 over time
        }
        if (Input.GetKey(KeyCode.A))
        {
            CarPosition = new Vector3(-250, 0) * Time.deltaTime; //X axis altered by 250 over time
        }
        if (Input.GetKey(KeyCode.D))
        {
            CarPosition = new Vector3(250, 0) * Time.deltaTime; //X axis altered by 250 over time
        }

        // loop through each boundary and check if the new translation would intersect the walls
        for (int i = 0; i < Boundary.Length; i++)
        {
            if (new Bounds(GetComponent<Collider>().bounds.center + translation * Time.deltaTime, GetComponent<Collider>().bounds.size).Intersects(Boundary[i].bounds))
            {
                //if the collision is detected, return the method here
                return;
            }
        }
        // else add the translation to the car
        transform.Translate(CarPosition);
    }    
   
   
}

Where’s the problem?

I don’t see where the variable translation ever gets set/changed so translation is always a vector of 0,0. Shouldn’t it be CarPosition in the Bounds check or something else

Ideally you want to check if the next car position will intersect the bounds and if it does, don’t move the car as you have reached your limit in that direction.

Sorry, could you show me what you mean?

You created this
[

Vector3 translation = new Vector3(0, 0);

Then at this point, you used the variable ‘translation’ but it’s still only a Vector3(0, 0). Did you mean to do that? Why would you need a Vector3(0 ,0) in the Bounds? Is the variable ‘translation’ used below supposed to be ‘CarPosition’?

// loop through each boundary and check if the new translation would intersect the walls
        for (int i = 0; i < Boundary.Length; i++)
        {
            if (new Bounds(GetComponent<Collider>().bounds.center + translation * Time.deltaTime, GetComponent<Collider>().bounds.size).Intersects(Boundary[i].bounds))
            {
                //if the collision is detected, return the method here
                return;
            }
        }

](http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Vector3)
Like

if (new Bounds(GetComponent<Collider>().bounds.center + CarPosition * Time.deltaTime, GetComponent<Collider>().bounds.size).Intersects(Boundary[i].bounds))