- Home /
Basic 2d movement problem: glitching in terrain
Hello, I have a problem. I'm making a 2d platformer, but when I move I glitch into a wall if I stand next to it and try to move. My player is, like my walls, just a cube. How do I solve this problem, so my player doesn't glitch into walls. So he just stays still, even if I try do move him into the wall?Thank you, -Nelis
#pragma strict
//Variables
var MovementSpeed : float = 0.1;
var JumpHeight : int = 350;
var SecsBetweenJumps : float = 1.5;
//Booleans
var CanJump : boolean = true;
function Start () {
}
function Update () {
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Translate(Vector3.left * MovementSpeed);
}
if(Input.GetKey(KeyCode.RightArrow)){
transform.Translate(Vector3.right * MovementSpeed);
}
if(Input.GetKeyDown(KeyCode.UpArrow) && CanJump){
Jump();
}
}
function Jump(){
CanJump = false;
rigidbody2D.AddForce(Vector3.up * JumpHeight);
yield WaitForSeconds(SecsBetweenJumps);
CanJump = true;
}
Comment