I need an orbit type thing for a game I'm working on.
Posted: Fri Mar 18, 2022 8:24 pm
Can someone please help me with making a UFO orbit a planet. I need it so the the ufo will obit the planet when the scroll wheel in spun.
Code: Select all
function love.load()
...
ufo = {} --we define our ufos data
ufo.radius = 100 --radius of the circle
ufo.x = 0 --vertical positon of the ufo
ufo.y = 0 --horizontal postion of the ufo
ufo.angle = 0 --initial angle
ufo.image = love.graphics.newImage('ufo.png') --image for drawing
ufo.speed = 0 --speed of movement
end
function love.update(dt)
ufo.angle = ufo.angle + ufo.speed*dt --this changes the angle based on the speed of the ufo
ufo.x = love.graphics.getWidth()/2 + math.cos(ufo.angle)*ufo.radius; --heres the math stuff for x
ufo.y = love.graphics.getHeight()/2 + math.sin(ufo.angle)*ufo.radius; --and for y
ufo.speed = ufo.speed * 0.9 --makes the ufo have a S M O O T H effect, so it looks NICE
end
function love.draw()
...
love.graphics.draw(ufo.image,ufo.x,ufo.y,0,2,2,16,16) --here we draw our ufo! :D
end
function love.wheelmoved(x, y)
...
ufo.speed = ufo.speed + y*2 --this changes the ufo speed, so you actually can move it
end
Code: Select all
love.graphics.circle('fill',ufo.x,ufo.y,10)
Code: Select all
if y > 0 or y < 0 then
...
end