Finding target position for particle system based shooting
Hey guys, I need your help :) I am trying to figure out spell shooting with mouse aiming. Basically I need to allow the player to shoot anywhere even if there is nothing they are shooting at. (So that they can anticipate the enemy's movement). I have a spherical world where the player can fly in 3D and the camera follows him. (So 3rd person but I can change it to first person if it would help) I can't figure out how to translate the mouse position to the target position of the spell shooting function. This is my spell shooting function:
/// <summary>
/// Shoots particle system in target position
/// </summary>
/// <param name="position"></param>
virtual internal void Activate(Vector3 origin,Vector3 target)
{
if (spellType == SpellType.Flying)
{
particle.transform.position = origin;
particle.transform.LookAt(target);
Instantiate(particle);
}
else
{
//In place spell appears at target location
particle.transform.position = target;
particle=Instantiate(particle);
timeLeft = SpellAnimationPeriod;
started = true;
}
}
I tried using rays but it only worked if it hit something and even then the aim was off. I also tried the ScreenToWorldPoint function of camera but it still didn't work. Thank you so much in advance.
Comment