I whipped up a small example which hopefully will show what i want to achieve.
I'm trying to get an object to travel along a defined bezier curve, but having trouble figuring out how i would do this.
Basically, i want to plot 2 points, then move an object between them.
Using https://love2d.org/wiki/BezierCurve:render
I attached an example below, you can press space to reset/random points.
I have also tried fiddling around with this:
https://love2d.org/wiki/BezierCurve:evaluate
Which mentions about "move objects along paths", but i do not understand it.
Here's the code in the attached love file:
Code: Select all
function love.load()
setRandomPoints()
end
function setRandomPoints()
--source point
x=love.math.random(200,love.graphics.getWidth()-200)
y=love.math.random(200,love.graphics.getHeight()-200)
--destination point
dx=love.math.random(200,love.graphics.getWidth()-200)
dy=love.math.random(200,love.graphics.getHeight()-200)
curve = love.math.newBezierCurve(
x,
y,
x*1.5- x/1.5,
dx,
dy
)
ball = {}
ball.x = x
ball.y = y
end
function love.draw()
love.graphics.setColor(150,150,150,255)
love.graphics.line(curve:render())
love.graphics.setColor(0,160,100,255)
love.graphics.circle("fill", ball.x, ball.y, 5)
end
function love.keypressed(key)
if key == "space" then
setRandomPoints()
end
if key == "escape" then
love.event.quit()
end
end