so i am making a game with a procedurally generated random path. my code so far is:
Code: Select all
pathoffset[1] = (pathoffset[1] + (dt * (love.math.randomNormal() + 1/4) / 3)) % 2
pathoffset[2] = (pathoffset[2] + (dt * pathoffset.multiplier/2)) % 2
local newpathval = math.sin(pathoffset[1] * math.pi * pathoffset.multiplier)*pathoffset.multiplier + math.sin(pathoffset[2] * math.pi)
newpathval = 175 + lume.round(newpathval * player.width)
local temppath = lume.concat({newpathval}, path)
path = lume.slice(temppath, 1, 350)
while this does work well, there are 2 thigs i dont like:
1. at the start there is just a random big "spike" in the path (everytime, no idea why)
2. the path is somewhat "shaky" in some parts, would like to make it "smoother"
does anyone know how to help pls thanc very much
EDIT:
in the attachments is a picture from the actual game that pretty much shows both of the problems
EDIT2:
ive realized ive explained how it works a bir too vaguely, so here it is:
the 2 pathoffset variables are for 2 separate sinus functions controlling the curve
the path variable is a list of all the points in the path (basically the key is the y-coordinate and the value itself is the x-coordinate)
so i update the curve, create a new point, then add it to the beginning and delete the last point to essentially move the path forward
hope this helps any *awesome* person who tries to help me!