How do I measure the distance between the edge of différents objects

0 favourites
  • 5 posts
From the Asset Store
On the Edge is a puzzle game where you have 40 levels to have fun with.
  • how can I measure the exact distance between the edge of several objects of the same family?

    Let me explain, in my games there are many objects (100+) of the same family but of different shapes and sizes (all are immobile)

    when creating the scene I chose a random object and I would like the colors of the others to be a gradient based on the distance they have with the "SelectedObject" so I tried to do Distance(SelectedObjectX,SelectedObjectY,FamilyX ,FamilyY) but the problem with this command is that it is based on the point of origin and therefore in my example if the pink object is the selected object then the command will say that the green object is closer than the 'purple object and that's not what I want, so I would have to use the collision polygon but I don't know how to do it

  • There isn’t a super simple solution to that. There is an algorithm called gjk that gives the distance between objects. There’s also mpr that could possibly do that too but there’s less info online about that.

    Worst case you could loop over all the points and edges of both objects and measure the distance between them. The lowest would be the distance. Just point distances could be good enough.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • thanks for the reply, unfortunately just pointing the distance doesn't work for what I want. to make it simple, it's a geography game and one of the game modes is to guess a country randomly selected. So you have a map with every country in white then you enter a country name and the redder it is, the closer you are. For example if the country chosen at random is Germany if you enter Poland I want Poland to be very red, but if you enter Brazil I want it to remain white... But some countries like Russia are so big that using the distance command does not work)

    I also thought about a loop but I was afraid it would impact performance and to be honest I'm not sure how to do it properly

  • A slightly different approach would be to list the neighboring countries for each country and do some kind of path finding with that. Then you’d color the country you clicked on based on the number of countries away you are.

    Again I don’t have a simple solution for that either. You’d need some kind of node based pathfinding.

  • I like this idea, it's something I've never used on construct so I'll try to learn about it and see the feasibility but the approach seems interesting to me, thank you very much

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)