- Home /
Drawing Lines For Lasers
Hello, everyone! I have a 'laser gun' on a space ship in my game. The cursor is a reticle used for aiming in my game.
When I click on an object, I'd like to have a line drawn from point 'a' (a predefined variable (the ship)) to point 'b' (The object I click on in 3D space)
How would I do this? Thanks!- YA
I want it like this: http://www.youtube.com/watch?v=jaHtALFflF8
Go to 1:06 to see him shoot
I'm not sure what you actually want since what you describe here is something different from what you can see in the video. In the video they use "laser-projectiles". Just a short line or another object (something like a long capsule with a glow / transparent shader) which behaves like a projectile (so it moves towards the target).
Your description is more like real lasers like in homeworld(youtube)
Sorry sir I definitely want a projectile. I thought that possibly making a line and scrolling the texture would do it... If there is a better way please tell! Thanks! -YA
Answer by asafsitner · May 06, 2012 at 10:31 AM
I believe a LineRenderer would be the best solution for that. Use SetPosition to set the start and end points of the renderer.
Edit:
If you click on an object you can find it's center with collider.bounds.center
.
If you click in empty space, well then, do you still want to fire a laser that way? You may be able to find the position in space by using `Camera.ScreenToWorldPoint`.
This is all fine and dandy, but how do I find the center of an object that I click on in 3D space? And what if I just click in empty space? Thank you so far for the help guys! -YA
Your answer
![](https://koobas.hobune.stream/wayback/20220613071135im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting (Input) values before running rest of script. 0 Answers
How can I leave a trail/tracks behind a character? Part 2 4 Answers
Keeping the player inside the screen? 2 Answers
Draw a Vector line ??? 3 Answers
How spaces works in unity? 1 Answer