Collision in Topdown 2D Project

Hi everyone,
I am attempting to make a turn based 2d topdown dungeon crawler (like Tales of Maj’Eyal or Dungeonmans) as my first Unity project.
I am an absolute beginner when it comes to game development and coding.

I have WASD grid based movement working for my character and I attached a 2D Box Collider and a 2D Rigidbody (do I even need this?) to it. Same thing I did with the walls it is supposed to collide with, but it’s not working, the character just moves over the wall and nothing happens.
I read somewhere that the collision system is supposed to work without any code, is this true for my case?

Here is my code for the character controller:

using UnityEngine;
using System.Collections;

public class PartyController : MonoBehaviour {

    private Vector2 pos;
    private bool moving = false;

    void Start () {

        pos = transform.position;
    }

    void Update () {

        CheckInput();

        if(moving) {

            transform.position = pos;
            moving = false;
        }
    }

    private void CheckInput() {

        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) {
            pos += Vector2.right;
            moving = true;
        }

        else if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) {
            pos -= Vector2.right;
            moving = true;
        }
        else if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) {
            pos += Vector2.up;
            moving = true;
        }

        else if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) {
            pos -= Vector2.up;
            moving = true;
        }
    }
}

Any help would be much appreciated!

seiesos

First off all, yes, if you want collisions to register you will need that Rigidbody2D and the Boxcollider. Also, yes the collisions should work more or less automatically.

Your problem is probably due to the fact that you use transform.position to move. From the physics point of view this is akin to teleporting your player. Which may very well result in your player moving through walls. Try to use Rigidbody2.MovePosition instead. This should take colliders into account.

Yes, that is the problem, but do you even need physics when you move only in grid? What about checking from an array if that position has wall in it?
Also you just add to the pos and move the player, but what if there is a wall, and he bounces or returns back? You now have your pos variable in the wrong position. Physics will stop the player from moving, but it will not return your variable to where it was.

You can still try this project on Unity Store which handle already everything about the 2D TopDown.
Asset Store

Or try the Web Demo.
Demo

You can also check out this video showing the gameplay.
Youtube

Best regards,

If all things move on a grid and there are no occasions where something might collide in between grid point, then there shouldn’t be any need for physics collisions. Having the level/map data in an array is an easy way to handle games based on grids.

You would have to check the player’s transform.position to see where it is. This is always up to date with the actual position of the player, no matter if it has bounced or been stopped by something.