What would be the best/most efficient way of getting the amount of similar connected dynamic objects.
In this image there is three “groups” of yellow balls and two groups of green balls. The Objects float about and I would like the numbers to update on the objects as the collide or break free in realtime.
For example: IF the lower green balls (The two that have the number two on them) collide with the other green balls (that say 6) they would all change number to 8. and if that group fell apart with 5 in one group and 3 in another the balls in the group of 5 would say 5 and the other 3.
Ive been putting the transforms (with tags per colour) in seperate lists and recursively looked what list they should belong to if they collide and break free but I doubt this it the most efficient solution.
Anyone have any insanely smart solutions they would like to share?
What if you thought of them like water droplets instead? No one really thinks about a puddle of water as being 1000 individual drops- it has its own identity, but that identity is shared with each of the single drops that make up its structure. In other words, both a drop and a puddle are “volumes of water”, just different sizes. Using this logic, each set of connected spheres of the same color could create a dynamic entity that loses or gains volume as spheres attach themselves to it, or break off from it.
This is just my idea of the logic that I think I’d use in this situation, but as to the particulars of the programming I’d have to give it a lot of thought. I’m only sharing since perhaps my imagery by itself might assist you.
Thanks Lysander.
It’s a good way of putting of it.
That is kinda what I’m doing with the Lists at the moment.
I guess the next thing is to figure out the most efficient way of programming it since a ball can dissconnect from another ball and still be part of the same “puddle” through another ball. Or even a ball connected way down the line of connected balls.
Problem is I need to keep an overview of ALL balls EVERY frame and i have a feeling that itterating through all balls every frame is gonna be SLOOOOOOOOW
I’m assuming that the balls have a sort of “stickiness” or “gravity” to them that holds them in constant contact with eachother once they touch or get really close, otherwise they’d never be in contact for longer than a fraction of a second. That being the case, I don’t really see the need for a frame-by-frame check of the statuses of all of the balls in question, as “detaching” or “attaching” can be events, and those events can then propagate other events. You can likely let the physics engine do 90% of the work for you here and just use the built-in collider events (particularly the OnCollisionEnter and OnCollisionExit events) to trigger functions in your “groupings” script.
@DonLoquacious , You assume the right thing. The game has gravity so the OnCollisionEnter and Exit is where I should call the “recalculations”. You’ve given me some ideas so I’m gonna try it today. thanks