Hi - I want to figure out how to do this with scripting and not with a collider object - I have a cube which sits on top of a plane. Using certain keyboard keys it can move around within the scene, but I want to restrict it to the dimensions of the plane it sits on. How would I do this? Here’s my current code (no bounds):
var speed : float = .01;
var newObject : Transform;
function Update() {
var moveRight = Input.GetKey(KeyCode.X);
var moveLeft = Input.GetKey(KeyCode.Z);
var moveBack = Input.GetKey(KeyCode.V);
var moveForward = Input.GetKey(KeyCode.C);
if (moveLeft) {
newObject.Translate(transform.right * -1 * Time.deltaTime * speed);
} else if (moveRight){
newObject.Translate(transform.right * 1 * Time.deltaTime * speed);
} else if (moveBack){
newObject.Translate(transform.forward * -1 * Time.deltaTime * speed);
} else if (moveForward){
newObject.Translate(transform.forward * 1 * Time.deltaTime * speed);
}
}