How to implement a continuous raygun with curve

Hello there !

So I’m not entirely new to unity but I tend to have a very limited knowledge outside of scripting.

Im trying to implement some sort of raygun in a side-scroller space-themed shoot them up.

I’m trying to achieve a continuous ray to shoot the ennemies, but the trick behavior is that when you would move the ship up or down, it would “wave” the ray, and then that wave would get to the end of the ray (making it the new line).

Allow me to make a very sophisticated draw.

This would be the ship shooting straight:

9870747--1422750--one.PNG

And the after a movement (here, down) the beginning of the ray would still be in front of the ship but the old horizontal position would remain for a moment. 9870747--1422753--image_2024-06-03_195509765.png

That wave would then sort of “catch up” on the right overt time and eventually the new line would be straight again but at the new horizontal position.

So here I went in programmer mode thinking how the hell am i going to develop this, thinking about having an array of dots representing the coordinates of the line, and performing a local Lagrange polynomial (Lagrange polynomial - Wikipedia) to interpolate a line between the dots.

But to be honnest i can already see thousands of problems of the generated curve not behaving like i would like. So here i am turning to you (thank you for reading all that appreciate it).

I am searching for a way of achieving this effect, and franckly im not sure where to start :

  • Maybe scripting a line rederer would help and giving it the points trough a C# script ?
  • A more curvy wapproach seems the new spriteshape API but is it really adequate to have some gameplay around it next such as damage calcuation and such?
  • Maybe should I program it from scratch but there is a way better approache than mine ?

Basically im taking any idea or similar project you could have to help me trough this problem.

Many thanks for your help !
Friendly,
Kevin :slight_smile:

I think you’re overthinking this. The simple answer here is imagine if your ray doesn’t fire a “line” but rather lots of small little individual dots/bullets. In aggregate the small dots look like a line, but each one just travels on its own in a straight line at a constant speed. If you fire one of these dots once every small interval, you will get a continuous stream of them and they will behave as you explained. If you want, you can use a LineRenderer and use the position of each dot as a point on the line, and the LineRenderer will adopt the shape you desire.

4 Likes

You can use the particle system with the Trails module in ‘Ribbon’ mode.

1 Like

Allow me to compliment you on your sophisticated drawing.

I took a little whack at the simplest implementation of it… it has a few tricky bits, see the comments.

Look at the DemoLineBullets scene in my Proximity Buttons project.

9871284--1422885--Screenshot-MyGame-133619372557252080.png

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons

Hey there !

First thanks @PraetorBlue , thats what i sort of tried with “regular” sprites, just shooting them forward every frame with the update function. But it ended having holes in it when i moved up or down because the ship moves way faster than the generation of sprites in the update function, so i figured out just using a line renderer trough all of them would make curves but only mimic them in two or three straight lines

Thx @zulo3d i’ll look into it

Well @Kurt-Dekker I’m glad you appreciate my drawings and the unique caracteristic they’ve got, many thanks !

I’ll look into your project many thanks for the input !

1 Like