Hi, I’m new to Unity and I’ve got the bare bones of my game set up, but I’ve reached a problem that I can’t figure out how to fix. I have a cube that can move left, right and jump. (like a sidescroller.) The problem is, I can stand on top of platforms, but the cube doesn’t collide with the sides of platforms. Here’s my player code:
var controller : CharacterController;
private var jnum = 0;
private var jumping = false;;
function Update() {
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate(Time.deltaTime * 10, 0, 0, Camera.main.transform);
}
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate(Time.deltaTime * -10, 0, 0, Camera.main.transform);
}
if (Input.GetKey (KeyCode.A) && jnum == 0 && controller.isGrounded) {
jumping = true;
}
else if (jumping == true) {
jnum += 1;
if (jnum == 10) {
jumping = false;
jnum = 0;
}
if (jnum < 10)
transform.Translate(0, .5, 0);
}
}
function OnControllerColliderHit(hit: ControllerColliderHit){
if (hit.gameObject.tag == "Block"){ // check if it's the box collider
print("hit!");
}
}
Can someone please tell me how to fix this?
Thanks in advance!