I am trying to write a script which throws a Ball from your Camera, but flies to the direction of you cursor (Crosshair). I can not get it to work though…
What I am trying to build is the same as the throw in this game:
This is what I have got so far:
void FixedUpdate () {
if (Input.GetButtonDown("Fire1")) {
Vector3 mousePos = Input.mousePosition;
GameObject projectile = Instantiate(Input.mousePosition.x, Input.mousePosition.y, transform.rotation) as GameObject;
projectile.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0, 0, 2000));
}
}
It seems to throw my Ball right from the middle of the Screen, but you can not control it by mouse position.