codi-hacks / space-race

Love2D-based Spaceship Racing Game
Other
3 stars 0 forks source link

Improve gravity #63

Open jaythomas opened 2 years ago

jaythomas commented 2 years ago

Tweak gravitate system so the goldilocks zone is wider. When getting near a planet it is easy to get too close and fall in or to be too far and not get any meaningful gravitational effects from it. Gravity is based on the inverse square. During the last meeting we discussed a linear gravity dropoff would give you a wider band around a planet that could slingshot your ship without providing too much or too little gravity.

Zxynine commented 2 years ago

The inverse square law is a phenomena created by the 3d nature of the universe, if you imagine sending rays out acting as light from the origin, the frustum of a camera would take the shape of a rectangular pyramid. If we have a pyramid with side lengths of 3 and a height of 1, the surface area of the base is just 3x3=9. Now if you imagine extending it outwards by a certain amount, the result would be a similar polyhedron, i.e. just a scaled version of the original. Because of that, all edges must be multiplied by the same scalar. So by doubling the height, you also double the length of the side. So while the height is now 2, the surface area of the base is (3 x 2) x (3 x 2)=36. Now if we were to look at the same problem in 2d space, the equivalent is a triangle with a base of 3 and height of 1. Same rule applies, extending the triangle (increasing the height whilst leaving the angles the same) you just get a scaled triangle. So by doubling the height to 2 you have a base of 6. The problem is that since there is no third dimension, the area the light hits is a line (the base of the triangle). Therefore, under the constraints of a 2d reality, light intensity, sound drop-off, and in this case gravity are all linearly proportional to the change in distance as opposed to in three dimensions where it follows the inverse square law. This is why a linear drop-off would feel more natural for this game. Because in a way it is.

jaythomas commented 2 years ago

Thanks for the 3D analogy. We had a "how" and now we have a "why" too.

Jon-Cavaliere commented 2 years ago

I think we should assign this issue to @Zxynine 🤣

Zxynine commented 2 years ago

I think we should assign this issue to @Zxynine 🤣

I would advise against that unless you want C# code in your lua project lol. Ive never used lua before. Maybe Ill throw some python or javascript in there for good measure. Variety is the spice of life as they say.

wyatt-herkamp commented 2 years ago

I think we should assign this issue to @Zxynine 🤣

I would advise against that unless you want C# code in your lua project lol. Ive never used lua before. Maybe Ill throw some python or javascript in there for good measure. Variety is the spice of life as they say.

If you know how to speak English you can write Lua

If you can program and speak English you are a expert lua dev