How do I keep the player with rigidbody from going through the wall

My problem is that when the player hits a wall, it ignores it as if it is not an object. both objects have a collider and the player has a rigidbody. This is my script

c#

using UnityEngine;
using System.Collections;

public class Game : MonoBehaviour {

public float speed = 0.3f;
public Rigidbody rb;
public GameObject floor;

// Use this for initialization
void Start () {

	rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update () {

	if (Input.GetKey (KeyCode.D)) {

		rb.MovePosition(transform.position + transform.forward * speed);

	} else if (Input.GetKey (KeyCode.A)) {

		rb.MovePosition(transform.position - transform.forward * speed);
	}

	if (Input.GetKey (KeyCode.Space)) {

		Destroy (floor);

	}

}

}

If your character isn’t moving too fast, and its collider and the wall collider’s layers are set to collide.

Your character might ignore other colliders if your character’s rigidbody is kinematic.