Page 1 of 1

Gravity Balls!

Posted: Tue Sep 30, 2014 1:04 pm
by Tjakka5

Re: Gravity Balls!

Posted: Tue Sep 30, 2014 2:03 pm
by Doctory
its quite something ;)
why wont you share the code >:C

Re: Gravity Balls!

Posted: Tue Sep 30, 2014 2:19 pm
by Tjakka5
I might later, if I get some more things done like, cleaner code, camera module, and a stable orbit :p

Example of "bad" code:

Code: Select all

function planet.update(dt)
	for i, v in ipairs(planetMap) do
		local dist = math.sqrt((v.xPos - player.xPos)^2 + (v.yPos - player.yPos)^2)
		if dist <= v.inf + 4 then
			v.isColliding = true
			local angle = math.atan2((v.yPos - player.yPos), (v.xPos - player.xPos))
			player.addVel((v.gravity*(v.inf*0.01)*math.cos(angle)), (v.gravity*(v.inf*0.01))*math.sin(angle), dt)
		else
			v.isColliding = false
		end

		for i, f in ipairs(planetMap) do
			if v ~= f then
				local dist = math.sqrt((v.xPos - f.xPos)^2 + (v.yPos - f.yPos)^2)
				if dist <= v.inf + f.inf then
					local angle = math.atan2((v.yPos - f.yPos), (v.xPos - f.xPos))
					planet.addVel(f, (v.gravity*(v.inf*0.01)*math.cos(angle)), (v.gravity*(v.inf*0.01))*math.sin(angle), dt)
				end
			end
		end
		planet.move(v, dt)
	end
end

Re: Gravity Balls!

Posted: Tue Sep 30, 2014 11:44 pm
by veethree
I made something similar a while back. The gravity calculation is a dirty implementation of Newton's law of universal gravitation. Collision is handled by love.physics.

You can spawn objects with the mouse, Right click for static, left click for dynamic.
With dynamic objects you can also click and drag to spawn them with some velocity.

Code could be cleaner. There's probably mad bugs. Look at the source at your own risk.

Re: Gravity Balls!

Posted: Wed Oct 01, 2014 4:09 am
by HugoBDesigner
Nice little concept! I also made something similar a while ago (you can still find it HERE), but yours seems a lot more "professional" than mine (mine was just a random doodle, but still).
Am I the ONLY one who thought it was a pun about Gravity Falls?

Re: Gravity Balls!

Posted: Wed Oct 01, 2014 7:45 am
by Tjakka5
HugoBDesigner wrote:Nice little concept! I also made something similar a while ago (you can still find it HERE), but yours seems a lot more "professional" than mine (mine was just a random doodle, but still).
Am I the ONLY one who thought it was a pun about Gravity Falls?
Actually, that is correct! xD

Re: Gravity Balls!

Posted: Wed Oct 01, 2014 9:45 am
by Robin
HugoBDesigner wrote:Am I the ONLY one who thought it was a pun about Gravity Falls?
Didn't think it was a pun, but I was confused for a bit.

Re: Gravity Balls!

Posted: Wed Oct 01, 2014 10:10 am
by Tjakka5
I recoded some stuff, made things neater, removed the player completely (Because it was basically a "ball" with no gravity) and added 3 cool things.

1. Ooooh snap, collision detection and resolving... somewhat.
It's very basic, and not good, and it even has a bug which is now a feature, and that is...
2. ...MERGING PLANETS!
Oooooooh snap.
Planets can now merge together because of their gravity and create a planet with triple or quadruple of infinitly its gravity. Dayum
3. Oh, and some lines between planets which are in their spheres of influences. meh.

Also, binary orbits! Whoo
https://www.youtube.com/watch?v=LGnyJyt ... e=youtu.be