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