Height of Mouse to Determine the Angle

Hi,

Currently, I am instantiating a projectile at a desired position in 3DSpace via the following line of code:

GameObject instPrefab = (GameObject)Instantiate(Prefab,
                         new Vector3(transform.position.x,
                                     transform.position.y+20,
                                     transform.position.z), 
                         Quaternion.identity);

/*instPrefab.transform.rotation =
      Quaternion.Euler(transform.rotation.y+(Input.mousePosition.y*factor),
                       transform.rotation.x,transform.rotation.z); // no angle
instPrefab.rigidbody.velocity = transform.TransformDirection(Vector3.up * 200);
// is instantiated in front of the player*/

instPrefab.rigidbody.velocity = CurrentSpell.transform.TransformDirection(
                                    -Vector3.forward*200); // gives an angle
instPrefab.rigidbody.velocity = transform.TransformDirection(Vector3.up * 200);
// not instantiated in front of player

It seems like I can get the angle, but the projectile isnt in front of the playerm and when I can't get the angle, the projectile is in front of the player.

I thought I could get it angled by modifiying the prefabs rotation (after instantiation) like this:

But I am not seeing any angle for when I move the mouse up and down..

You would use the rotation Quaternion of the Instantiate. Probably something like:

public float rotationRange = 90.0f; //degrees
float factor = 1.0f;

public void Start() {
    factor = rotationRange / Screen.height;
}

//Somewhere else
Instantiate(prefab, position,
            Quaternion.Euler(Input.mousePosition.y * factor,0.0f,0.0f));

Or if you want something more directly related, you could convert the mouse position into a world coordinate and then point at it.

//depth is how far from the camera you want the aimPosition to be
Vector3 aimPosition = new Vector3(0.0f, Input.mousePosition.y, depth);
aimPosition = Camera.main.ScreenToWorldPoint(aimPosition);
Instantiate(prefab, position, Quaternion.LookRotation(aimPosition));