Collisions not working in top-down RPG?
Hi guys, so I've been having this problem on Unity 2D when I try to add collisions into the game. Not trigger collisions, just collisions in which you run into a wall and it stops you and whatnot. I've added a Ridgidbody 2D and BoxCollider2D component to both the player (blue rectangle) and the wall (orange rectangle). However, when I control the player object to move into the wall, it just walks right through it.
I've grown desperate trying to solve this dilemma, but unfortunately this site won't let me upload a single image file, so I can't show what my project looks like. Instead, I'll just include the player movement script (I have a feeling the problem may be here). Thanks for helping, guys.
Below is my player controller script, attached to the blue rectangle:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { //Movement variables public float speed; private Rigidbody2D rb; private Vector2 moveVelocity; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (Input.GetKey("space") == false) { moveVelocity = moveInput.normalized speed; } else //Running while space is held { moveVelocity = moveInput.normalized speed 2; } } void FixedUpdate() { rb.MovePosition(rb.position + moveVelocity Time.fixedDeltaTime); } }