Problems with magnet in grid based puzzle game
I've been fighting with this magnet for ages, but basically a metallic object can try to be magnetized by up to 4 magnets simultaneously. The way I have it setup atm is the metallic object sends scans in every direction (not diagonal) looking for magnets and once it finds one, it calculates the empty slots between them and adds the direction (vector3) and corresponding empty slots (int) to a dictionary.
After all of the magnets are added to the dictionary, then comes the difficult part. First I completely delete opposing magnet entries with duplicate empty slot values, as they cancel each other out. Next I need to find out which value is smallest. If there's only one, I just move the metallic object in that direction by a slot and repeat the process. If there's more than one minimum value, I need to find out if they have opposing magnets. If they do, then I need to calculate how far those opposing magnets are, and the one with the furthest opposing magnet "wins", as it has the stronger magnetic pull.
Basically I'm not sure if I'm going about this the correct way, as in using dictionaries and calculating everything after I've scanned for the magnets. I've never used dictionaries before, so I'm not even sure how to retrieve the direction (key) with the smallest empty slot value and use it. Any help is appreciated!
Your answer
Follow this Question
Related Questions
How to determine the number of bubbles that share that same color in a cluster and return as a list? 1 Answer
Newbie trying to undestand unity 1 Answer
Can't get roll-a-ball behavior script (my first script) to work... 1 Answer
Changing variable if there are many scripts. 0 Answers
how do I rezolve "look rotation viewing vector is zero"? 1 Answer