this post was submitted on 21 Sep 2025
17 points (100.0% liked)

Godot

7105 readers
17 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 2 years ago
MODERATORS
 

I'm making a game where there are many Area2Ds of different countries, but I want to know the size of each country to calculate their surrender limit (bigger countries take longer to surrender, for example).

I don't want to find the area of just one collision2D as some countries have multiple (see island nations, overseas colonies...), but looping that with the children could work if finding area using AREA2ds isn't a thing.

I don't want to simply use the outermost points of a collisionshape2D and draw a big rectangle, as it would make some countries way bigger than they really are (see especially the British and French empires)

Is it possible to find the area of an Area2D? If not, is it possible to calculate the area of CollisionShape2Ds (then I could just loop through the children).

p.s. Country size will not be the only factor for surrender limit, things like equipment stockpiles and something similar to war support in HOI4 might also affect it...

you are viewing a single comment's thread
view the rest of the comments
[–] gjohnson@programming.dev 1 points 2 weeks ago* (last edited 2 weeks ago)

Good afternoon! While, I'll be honest, I don't do much video game development as I'm finishing up my Master's program in Computer Science and my Data Science graduate certificate, the best advice I can give you for purposes regarding this problem is to look to the Riemann Sum formula regarding approximation of definite integrals on a two-dimensional plane, which is presented as follows:

∑ᵢ=₁ⁿ f(xᵢ)Δx

(P.S. - This formula was copied and pasted via generative AI, as I struggled to figure out how to write formulas in Lemmy response windows)

I suggest this as the imperfect dimensions of the sizes of countries on a global map appear to suggest necessity of calculations of area by means of integral calculus. While I was exposed to these formula during my high school AP Calculus course several years ago, I will admit I had to look it up again on Google and was reminded with an AI-generate response. Basically, the integral of an imperfect shape that cannot be defined by algebraic equations can be approximated on a curve with a series of rectangle of varying heights with equivalent widths. The more rectangles are placed to approximate the curve, the more accurate your assessment becomes. So, if you're trying to approximate the size of the country on your global map for purposes of a country-surrendering mechanic in your game via Godot Engine, I would highly suggest defining a method that takes in the standard width of all rectangles present in your graph (each represented as a distinct CollisionShape2D component/element) with heights extending just beyond the outline of the country's graph, and returns the approximate summation of the country's area as a whole in a two-dimensional context for purposes of applying your country's surrender limitation game mechanic.