I have my Player with a box collider 2D and have placed boxes in grid like placement, just like Bomberman has. When I try to move through them, the movement is supremely jagged and very jittery because the Player collides with the boxes that do not allow it to move inside the lane. How can I create a motion that smoothens this out and allows for smoother turns in and out of the lanes ?
For better explanation, kindly check the 120kb screen captured video HERE.
Here is the script that I made for the navigation for the Player.
public class PlayerMovement : MonoBehaviour {
public bool horizontalPressed;
public bool verticalPressed;
void Start(){
horizontalPressed = false;
verticalPressed = false;
}
void Update() {
transform.position += transform.up * 10 * Time.deltaTime;
if (!horizontalPressed){
if (Input.GetKey(KeyCode.W)){
transform.rotation = Quaternion.identity; transform.Rotate (0, 0, 0);
verticalPressed = true;
}
else if (Input.GetKey(KeyCode.S)){
transform.rotation = Quaternion.identity; transform.Rotate (0, 0, 180);
verticalPressed = true;
}
else verticalPressed = false;
}
if (!verticalPressed){
if (Input.GetKey(KeyCode.D)){
transform.rotation = Quaternion.identity; transform.Rotate (0, 0, 270);
horizontalPressed = true;
}
else if (Input.GetKey(KeyCode.A)){
transform.rotation = Quaternion.identity; transform.Rotate (0, 0, 90);
horizontalPressed = true;
}
else horizontalPressed = false;
}
}
}