How to add explosion force to player?

I trying to creat object that emits gravity fields. I read about it and i think the best way for it is to use addExplosionForce, but i really dont know how to use it.

I have player with rigidbody, characater controlle and my own movement script, and sphere with localGravityScript. This is my code but it don’t work:

	void Update () {
		Vector3 location = transform.position;
		Collider[] objectsInRange = Physics.OverlapSphere(location, radius);

		foreach (Collider col in objectsInRange) {
			Rigidbody player = col.GetComponent<Rigidbody>();
			if(player != null){
				Debug.Log("inside sphere");
				player.AddExplosionForce(4, location, 5);
			}
		}
	}

my target is to create effect of local gravity field, if player enter inside field he should be pulled inside or pushed outside.

The problem is your rigid body is kinematic, aka animated. So in order to have your rigid body be active, you need to disable kinematic. This, however, will not allow you to control your character. So now you realize why we can’t always use rigid bodies for player characters. BACK TO THE DRAWING BOARD!

So instead of that, just calculate it yourself and apply it to your move vector before using CharacterController.Move. Something like this:

Vector3 velocity;

void FixedUpdate()
{
  UpdateInput();
  UpdatePhysics();

  controller.Move( velocity );
}

...

void UpdatePhysics()
{
  Vector3 gravity = Vector3.zero;
  foreach (Planet p in planets)
  {
    //todo, calculate distance from me to planet
    //based on distance, add to gravity in direction of planet
    //add gravity vector to velocity
  }
}

So essentially, create your own physics. Pretty simple with things like gravity and basic input. Gets more complicated as you go, but gives you total control of your movement vector for each update. Best solution I’ve found. Hope this helps!