Raycasting from an object to a mouse click point

I’m trying to write a simple script to add force to an enemy character. I’d like to get the raycast to come from a gun object, but I made it go from the camera for now. The problem is that it does not add force to the enemy character. It adds force to a cube I placed in the scene as a test, but not the enemy character. The character has a rigidbody, and I’ve tried putting a mesh collider and a box collider on it. None of them work. Also how would I get it to cast from a game object’s transform? Here is my current code:

using UnityEngine;
using System.Collections;

public class RaycastShot : MonoBehaviour {

public float range;
public float power;

// Use this for initialization
void Start () 
{

}

// Update is called once per frame
void Update () 
{
if(Input.GetMouseButtonDown(0))
{
	
	Ray sniperShot = Camera.main.ScreenPointToRay(Input.mousePosition);
	RaycastHit hitInfo;
	
	if (Physics.Raycast(sniperShot, out hitInfo, range))
	{
		Debug.Log("You are shooting");
		Debug.DrawLine(sniperShot.direction, hitInfo.point);
		if (hitInfo.rigidbody != null)
		{
			hitInfo.rigidbody.AddForceAtPosition(sniperShot.direction * power,hitInfo.point);
		}
	}
}

}

}

that code for addforce should work in principle,perhaps the force is is simply too small and the mass of the object too large to be moved, perhaps its got its position or rotaiton locked or is kinematic is checked which is basically similar. perhaps your using a character controller and not a rigidbody, you need to show the screen maybe or something to know.

to shoot from the gun.

Ray LaserGunRay;

LaserGunRay.origin = gunbarrel.transform.position;
LaserGunRay.direction = gunbarrel.transform.forward; //assuming you oriented it right