Question by
jigwiz · Mar 28, 2017 at 02:01 AM ·
shootinglinerendererforward
linerender shoots in center of screen
I have a character shooting a ray using the linrenderer. I have empty game object attached to the character and this is what the linerenderer is attached to and what is shooting the ray. The linerenderer shoots forward but for some reason it shoots (line ends) at point in center of screen no matter where the character moves to. It should be shooting forward in a direction relative to the character. I tried rotating character to test, though the ray shoots forward it still shoots at single point in space. How can I get the linerenderer to shoot at corrects places? Heres code:
public float weaponRange = 300f;
public Transform gunEnd;
private LineRenderer laserLine;
void Start ()
{
laserLine = gameObject.GetComponent <LineRenderer>();
}
void Update ()
{
if (Input.GetButtonDown ("Fire1"))
laserLine.enabled = true;
laserLine.SetPosition (0, gunEnd.position);
laserLine.SetPosition (1, (gunEnd.transform.forward * weaponRange));
if (Input.GetButtonUp ("Fire1"))
laserLine.enabled = false;
}
}
Comment