I researched a bit and I found out how to do normal lasers.
Now I was wondering about
...
...
this.
It curves nice and naturally there but what I really want is this possibility:
(It twists and turns, couldn't find the gif)
How to make curvy lasers
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: How to make curvy lasers
Looks like a job for splines/bezier curves. Not something I've dabbled with myself but I'm pretty sure they would help give this effect. A spline will just be something similar to a "path" though so to make the laser "thick" you might have to use it to to generate or deform a mesh.
I haven't watched it but I remember coming across a video a few years back by a well known solitary programmer which went into some detail about splines https://www.youtube.com/watch?v=9_aJGUTePYo
I haven't watched it but I remember coming across a video a few years back by a well known solitary programmer which went into some detail about splines https://www.youtube.com/watch?v=9_aJGUTePYo
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to make curvy lasers
You could fake it with multiple overlapping segments made up of small sprites (circular bullets for example), probably less computationally expensive in most cases, compared to evaluating bezier curves i believe.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: How to make curvy lasers
Maybe the same as lightning, just make the line not so straight.
viewtopic.php?p=249816#p249816
But add more points and smooth thre result line as
t2 = 0.25*t1+0.5*t2+0.25*t3 where t2 is actual point, 1 and 3 are previous and next point in line.
viewtopic.php?p=249816#p249816
But add more points and smooth thre result line as
t2 = 0.25*t1+0.5*t2+0.25*t3 where t2 is actual point, 1 and 3 are previous and next point in line.
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: How to make curvy lasers
You're all so helpful
I didn't know ....heheh... about Bezier curves until know and I was thinking that would be my solution but then it takes more CPU to call the evaluate function?
Don't really understand the "fake it" method so for now I'll try the lightning method and post how it goes, else I might just use the curves.
I didn't know ....heheh... about Bezier curves until know and I was thinking that would be my solution but then it takes more CPU to call the evaluate function?
Don't really understand the "fake it" method so for now I'll try the lightning method and post how it goes, else I might just use the curves.
Re: How to make curvy lasers
It's kind of like this:Gunroar:Cannon() wrote: ↑Sat Nov 05, 2022 9:22 am Don't really understand the "fake it" method so for now I'll try the lightning method and post how it goes, else I might just use the curves.
The closer together you draw each circle, the more it looks like a curvy line. If you put them so close they overlap enough, you end up with a solid curvy line. If you use a sprite instead of a circle, you get a curvy sprite line thing. In your case, a curvy laser.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: How to make curvy lasers
Oh...wow. I see. Just like how trails are drawn. Though won't I still get the path of where to draw these circles ... from a Bezier Curve?
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to make curvy lasers
you don't need a bezier if you just focus on the "first" sprite, since it has position and velocity, you can just duplicate that, and draw the duplicate in the old positions before you update the current sprite's position.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: How to make curvy lasers
Based on the lightning
Explanation:
1) You have one line AB.
2) Add the point C between them, so you have ACB. The point C is in the middle, but with small movement to the normal of line AB.
3) Add points D and E between A and C; C and B, so you have ADCEB.
4) I don't want to use the alphabet, so add points t1, t2, t3, t4 between last letters: A-t1-D-t2-C-t3-E-t4-B
5) repeat 4) until you want and make inserted points smooth to neighbour points.
Code: Select all
local function newLaser (x1,y1, x2, y2, sd)
-- d is amount of subdivisions, for example 3
sd = sd or 3
local p1 = {x=x1, y=y1}
local p2 = {x=x2, y=y2}
local points = {p1, p2}
for i = 1, sd do
local n = (#points-1)
local temp = {unpack (points)}
-- print ('i'..i..' n'..n)
for j = 1, n do
local point = getPointBetween (points[j], points[j+1])
table.insert (temp, j*2,point)
-- print ('inserted', #points, j*2)
end
points = temp
-- make the line smooth
if i > sd-4 then
local s = 0.4
for i=2, #points-1 do
local p1 = points[i-1]
local p2 = points[i]
local p3 = points[i+1]
p2.x = 0.5*s*p1.x+(1-s)*p2.x+0.5*s*p3.x
p2.y = 0.5*s*p1.y+(1-s)*p2.y+0.5*s*p3.y
end
for i=#points-1, 2, -2 do
local p1 = points[i-1]
local p2 = points[i]
local p3 = points[i+1]
p2.x = 0.5*s*p1.x+(1-s)*p2.x+0.5*s*p3.x
p2.y = 0.5*s*p1.y+(1-s)*p2.y+0.5*s*p3.y
end
end
end
-- print ('#points', #points)
local line = {}
for i, point in ipairs (points) do
-- print (point.x, point.y)
table.insert (line, point.x)
table.insert (line, point.y)
end
local laser = {points=points, line=line, sd = sd}
return laser
end
1) You have one line AB.
2) Add the point C between them, so you have ACB. The point C is in the middle, but with small movement to the normal of line AB.
3) Add points D and E between A and C; C and B, so you have ADCEB.
4) I don't want to use the alphabet, so add points t1, t2, t3, t4 between last letters: A-t1-D-t2-C-t3-E-t4-B
5) repeat 4) until you want and make inserted points smooth to neighbour points.
- Attachments
-
- curvy-lasers-01.love
- (1.14 KiB) Downloaded 120 times
Who is online
Users browsing this forum: Bing [Bot] and 0 guests