I have Unity Pro 4.6.1 and I am trying to make a cube move with the arrow keys. Here are the barriers before I move the cube:
And here's when I move the cube (the problem):
I don't want the cube to go through the blocks, just inside them. Here is my moving code:
#pragma strict
static var selectedId : int;
static var speed : int = 5;
function Update () {
if (Input.GetKey (KeyCode.UpArrow)) transform.Translate (Vector3(0,0,1) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.DownArrow)) transform.Translate (Vector3(0,0,-1) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.LeftArrow)) transform.Translate (Vector3(-1,0,0) * Time.deltaTime*speed);
if (Input.GetKey (KeyCode.RightArrow)) transform.Translate (Vector3(1,0,0) * Time.deltaTime*speed);
}
How do I fix this?
EDIT: I modified my move code but it still goes through things:
#pragma strict
var speed : float = 10.0;
function Update () {
var horMovement = Input.GetAxis("Horizontal");
var forwardMovement = Input.GetAxis("Vertical");
if (horMovement) {
transform.Translate(transform.right * horMovement * Time.deltaTime * speed);
}
if (forwardMovement) {
transform.Translate(transform.forward * forwardMovement * Time.deltaTime * speed);
}
}