I need an orbit type thing for a game I'm working on.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 2
- Joined: Sat Mar 12, 2022 12:45 am
I need an orbit type thing for a game I'm working on.
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.
Re: I need an orbit type thing for a game I'm working on.
Hi!
For making the ufo orbit over the planet we need to use the most people's worst enemy...
MATH
anyways, i will leave the code and at the end the article i used for making this.
ok, so...
the load function makes a table that contains the ufo data,
the update function changes the ufo angle based on the speed it is going, uses math for moving the ufo and finally multiplies the ufo speed than 0.9, so it has a cool ice effect
the draw function draws the ufo, in my case i used an example image, but you can use or whatever you want
and finally, the wheelmoved function, we change the speed of the ufo based on the y velocity of the mouse.
also, you used
i dont know if there is some reason to check if the y is not 0, since that function only is called when the wheel is moved (y will never be 0, otherwise the fucntion is not called), but if theres no reason, then you dont need to check if y is not 0
anyways, heres the article i used for making the ufo orbit(aka: MATHS): https://gamedev.stackexchange.com/quest ... cular-path
hope it helped!
For making the ufo orbit over the planet we need to use the most people's worst enemy...
MATH
anyways, i will leave the code and at the end the article i used for making this.
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
the load function makes a table that contains the ufo data,
the update function changes the ufo angle based on the speed it is going, uses math for moving the ufo and finally multiplies the ufo speed than 0.9, so it has a cool ice effect
the draw function draws the ufo, in my case i used an example image, but you can use
Code: Select all
love.graphics.circle('fill',ufo.x,ufo.y,10)
and finally, the wheelmoved function, we change the speed of the ufo based on the y velocity of the mouse.
also, you used
Code: Select all
if y > 0 or y < 0 then
...
end
anyways, heres the article i used for making the ufo orbit(aka: MATHS): https://gamedev.stackexchange.com/quest ... cular-path
hope it helped!
Code: Select all
for i, v in pairs(problems) do
fix(v)
end
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests