Adding force in all directions to an object based on ray direction


I am trying to ‘flick’ a counter and I need it to be done so that the the player can flick it in the direction they are facing but with varying forces depending on where on the counter they have clicked/pressed.

At the moment this is the code I have to flick it is this:

    public float xPokeForce;
	public float yPokeForce;
	public float zPokeForce;

    void Update() {
        if (Input.GetMouseButtonUp(0)) {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			float xDir = ray.direction.x;
			float yDir = ray.direction.y;
			float zDir = ray.direction.z;
			Vector3 rayDir = new Vector3(xDir * xPokeForce ,yDir * yPokeForce, zDir * zPokeForce);
            if (Physics.Raycast(ray, out hit))
                if (hit.rigidbody != null)
                    hit.rigidbody.AddForceAtPosition(rayDir, hit.point);

This works to an extent but the results from clicking at the edge compared to in the middle are barely noticeable.

The picture is only a basic example as it would depend on how long/hard the user pressed on the object as to how it would react.

Any help would be good!



If you are using a flattened sphere, you can do this:

//Assuming raycast with a RaycastHit called "hit"
Vector3 force = Vector3.Scale(hit.normal, PokeForce);
hit.rigidbody.AddForceAtPosition(force, hit.point);

Hope this helps,