How to stop player pushing rigidbody(NPC)


I have a simple scene for testing purposes. I have a player with charactercontroller (from unity assets) which moves around a scene.

I also have a cube, which for represents an NPC with rigidbody. This is the script for my NPC:

using UnityEngine;
using System.Collections;

public class stop : MonoBehaviour {
	public float movementSpeed= 5f; 

	public GameObject target;
	void FixedUpdate() {
		Vector3 direction = (target.transform.position - transform.position).normalized;
		rigidbody.MovePosition(transform.position + direction * movementSpeed * Time.deltaTime);

The NPC moves towards a target at a set speed. The player and npc shouldn’t be able to walk through eachother and that is also working. However, if I go against the movement of the npc (npc moves downwards and if I move upwards) the player begins pushing the npc upwards across the map. Rigidbody has constraints(freeze position) but if I use freeze position along the path the npc walks, the player can no longer push it but it simply grinds to a halt. If I tick IsKinematic the player and npc begin walking through eachother.

How can I prevent this?

Any help is appreciated.

I think the problem you have is that you have 2 forces acting against each other. One way to solve this is through code where OnCollisionEnter() you check if you have collided with the NPC and stop movement if yes.