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:9288-issue.png

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?

1 Answer

1

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). :)

@Louis, You may be right, but he says in the question "forward on their Z axis," so I coded it this way. @Hyperion, if you mean forward of the character, then: Laser.SetPosition(1, Cero.position + Cero.forward * distance);

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? ![alt text][1] [1]: /storage/temp/9326-issue2.png

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)