Force for point to point

I have a ball with a rigid body that I want to shoot in the direction of a mouse click. The ball shoots but not in the right direction. Seems simple enough but I don’t think I am getting the direction that force is added right.

Here is what I am doing.

``````public Vector3 shootForce;
public float thrust = 10000F;
public Camera playerCamera;

protected void  Update() {

Vector3 mousePoint = playerCamera.ScreenToWorldPoint
Vector3 fromVector = transform.position;
shootForce = mousePoint - fromVector;
shootForce = shootForce.normalized * thrust * -1;
}
``````

Any suggestions are greatly appreciated.

Is there a way to get support from Unity to answer this question?

Yes, I believe it is something like \$150 per issue.

In your case, I would check if the z value the mousePoint vector is what you want it to be.
Just print out the mousePoint vector and see if it makes sense given your fromVector.

did u find the answer? cause i have the same qustion here? and i’m trying to know the position of the ball when it collides with the ground ? any ideas?

Another graphics developer did something that I don’t know and it started working without the -1 multiplier. I think it had something to do with the camera properties.

Camera.ScreenToWorldPoint probably doesn’t do exactly what you are expecting. The X and Y coordinates are the screen positions in world space, but the Z coordinate is actually the distance from camera of the rendered pixel at that screen point. If you fire an object to this point, you will get strange results, depending on what scenery you have in the background. You need to set the Z coordinate of the target point to zero (or whatever the Z position of the launcher is if not zero).

``````public Vector3 shootForce;
public float thrust = 10000F;
public Camera playerCamera;

protected void  Update() {

Vector3 mousePoint = playerCamera.ScreenToWorldPoint
Vector3 fromVector = transform.position;
shootForce = mousePoint - fromVector;
shootForce = shootForce.normalized * thrust * -1;