- Home /
laser simulation with line render and colliders
I am creating a laser that will be used as a projectile.
My current algorithm is this: 1. I have a projectile prefab that renders a line through 2 points as my laser. 2. When it is "fired" out of gun, the laser front position only moves forward, until it's length exceeds the laser size i want, then i use a bool to say it has left barrel 3. Then i move the front and back positions forward 4. when i raycast to the next position of the front, and it collides with something, i stop the front and keep moving the back. (i apply damage here) 5. I raycast between the front and back of the laser beam to determine if a ship intersects it, for which i split the laser and make another copy and set each laser front/backs to look as if it was one laser stream split in two
My problem: This only works if the ship doesn't move AFTER my laser does (or the ship moves within range of my laser's next move amount and the laser can stop).
If the ship moves after my laser does this raycast, the ship will be within the laser beam, and the beam splits (which is not wanted as this will happen over and over). I want my laser front to move backwards to simulate the laser colliding with the ship.
I could store which ship stops the laser initially, and next frame raycast backwards, and if its the same, move the front backwards, but if the ship never intersects the front and just hits the laser front from the side, the splitting problem happens.
How do I accommodate for this case? What is a good and efficient way to handle this laser movement and such that would also be acceptable for mobile?
Your answer
Follow this Question
Related Questions
How can i create a character like dragon hill game, Digging underground, what collider should i use? 0 Answers
Trouble making laserbeam with LineRenderer 0 Answers
Test line renderer collision? 1 Answer
How to check of a line renderer collides with ground ? 1 Answer
Mobile Build and Playmode Terrain Collision Disparity 0 Answers