How to move player like pacman in 2d? How to prevent coliision hit when played turned the corner?

Hello

I’m sorry if my question is a bit unclear.
I managed to give my player movements like pac-man yet if i want to turn the corner i want to make my player slide smoothly through the maze. However, with my movement script most of the time it hits the corner of the objects and can’t go between the objects . Also in my game can i make the distance of the objects as my player objects size? I want it to go between two objects and still move smoothly.

Sorry I asked a bit too much but I really couldn’t solve it.
Thank you.

My Movement script:

void FixedUpdate() {

         //Movement
         float h = Input.GetAxisRaw("Horizontal");
         float v = Input.GetAxisRaw("Vertical");
         if (Input.GetAxisRaw("Horizontal") > 0f || Input.GetAxisRaw("Horizontal") < 0f) {
             GetComponent<Rigidbody2D>().velocity = new Vector2(h, 0) * speed;
         }
         else if (Input.GetAxisRaw("Vertical") > 0f || Input.GetAxisRaw("Vertical") < 0f) {
             GetComponent<Rigidbody2D>().velocity = new Vector2(0, v) * speed;
         }
 
     }
 
     void OnCollisionEnter2D(Collision2D collision) {
         if (collision.gameObject.tag == "Obstacle") {
             GetComponent<Rigidbody2D>().velocity = Vector3.zero;
             GetComponent<Rigidbody2D>().angularVelocity = 0;
         }    
     }

If you want to use physics instead of coding the movement yourself, then use physics to stop your character as well. So I’d say remove the entire on CollisionEnter2D method.


Then your collision should stop you when running into walls. As for smooth sliding, add a circle collider to Mr. Pac Man, and put a Physics Material onto his collider that has friction set to 0 and set Friction Combine to Minimum

If you say moving like pacman, do you mean really moving like pacman? If so, you don’t even need collision. Pacman moves on a grid with every tile tile on it known (floor, block, pickup…). You can just use simple math to move him and around corners.