- Home /
Question by
eplaygame · Jan 01 at 05:20 PM ·
c#shootingscreentoworldpoint
Shot to the middle of crosshair?
Hi!
In the game I have a crosshair - not in the middle of the screen, it is a little bit above so that crosshair X - middle of the screen and Y middle + delta...), the crosshair doesn't move.
I am trying to shot the ball to the middle of the crosshair. Sometimes the ball goes ALMOST to the center of the crosshair but not always and it is really visible even though its just a 10-20px...
The code I use to get the center of the crosshair:
private Vector3 GetShotDirection()
{
Vector3 direction = Camera.main.ScreenPointToRay(crossHair.position).GetPoint(1000);
foot.CurrBall.transform.rotation = Quaternion.LookRotation(direction);
return direction;
}
AddForce:
foot.CurrBall.Rb.AddForce(foot.CurrPuck.transform.forward * force, ForceMode.Impulse);
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613051143im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
ScreenToWorldPoint and Mouse Position 2 Answers
Shooting script C# 1 Answer