- Home /
LineRendering Forward
Hi everyone,
I have robots that shoot lasers. Currently, they shoot at the character.
Laser.SetPosition(0, Cero.position);
Laser.SetPosition(1, Victim.position);
(BTW, Cero is the point out of which they're shooting.)But I want them to shoot forward on their Z axis. So I did:
Laser.SetPosition(0, Cero.position);
Laser.SetPosition(1, Vector3.fwd);
But instead of shooting on their z axis, they're shooting off to some random spot:
And in the picture, it's hard to see, but that robot is shooting to his right.
What's the issue, and is there a way to make them simply shoot a linerenderer forward?
Answer by robertbu · Mar 25, 2013 at 03:04 AM
I assume that "Vector3.fwd", you mean "Vector3.forward". Vector3.forward, is a zero based, and has a length of one, so you are pointing near the origin. I assume from your first two lines, that you have "Use World Space" checked in the line renderer. If so, you want these two lines instead:
Laser.SetPosition(0, Cero.position);
Laser.SetPosition(1, Cero.position + Vector3.forward * distance);
'distance' is a variable you set (or a constant you insert) that represents the distance in form of Cero you want the LineRenderer to end.
I think you want Cero.forward (forward relative to Cero) rather than Vector3.forward (forward relative to zero). :)
Thanks for your guys' help. Now I'm using
Laser.SetPosition(0, Cero.position);
Laser.SetPosition(1, Cero.position + Cero.forward * Lazdist);
And the lazer goes in the right direction. But now, the lazer isn't long enough, even if I change distance to 1000. What's the issue?
If this is answered, please accept the right answer, by selecting the tick under the thumbs down button :)
@Benproductions1: It hasn't been fully answered, but I of course will accept the answer when my second question has been answered (up above)