Projectile throw in 3rd person
I am throwing a projectile in third person view. The crossHair is the cursor in the game .Here's what i wrote:
Vector3 pos = new Vector3(crossHair.rectTransform.position.x, crossHair.rectTransform.position.y,
1.0f);
pos = Camera.main.ScreenToWorldPoint(pos);
ball.transform.LookAt(pos);
ball.GetComponent<Rigidbody>().velocity = ball.transform.forward * 20;
crossHair is an image element from canvas. I am instantiating the ball with
ball = (GameObject) Instantiate(projectile, transform.position, Quaternion.identity);
projectile is the ball prefab. This script is being attached to a simple cube. I just want the ball to go in the direction that the crossHair is pointing at, precision of hitting the target doesn't matters.
My problem with this piece of code is whenever i throw the ball it gets thrown at the back of the cube, means in the wrong direction not in the direction the crosshair is pointing at. However this script works well in first person, means I attached this script to a main camera and this works like a gem, but for third person it doesnt work. Please help. Thanks in advance
Your answer
![](https://koobas.hobune.stream/wayback/20220612050737im_/https://answers.unity.com/themes/thub/images/avi.jpg)