Whatever condition
>>Spread value 1 in object Alterable Value A
+Run fastloop (number of objects) times
On loop
+Object Value A = loop step
+Loopstep = 0 (or 1, can't remember the index)
>>Set counter to distance from player (using Sqr(Abs(Xobject-Xcharacter)(Xobject-Xcharacter)-(Yobject-Ycharacter)(Yobject-Ycharacter))
+Set counter value A to Object Value A
On loop
+Object Value A = loop step
+Counter is greater than distance from player
>>Set counter to distance from player
+Set counter value A to Object Value A
Then once the loop has run through, take the counter's Value A and you have the ID of the closest one. Alternatviely you could try using the Sort X extension to compare all the distances, however MMF2 is not starting for me so I can't check to see how it works or if the syntax of the distance formula I gave you is correct.
Sounds more or less right. If you got duplicates of both object types, then it's going to be a pain, but I don't see any way around that.
Someone really needs to make an MMF2 version of the "Value Finder" extension.
That distance formula is wrong, but I'm sure Solgryn can figure it out. You know there would be no point having the "Abs()" there because a square-root will always come out positive. Of course, since we're only interested in the relative distance, there's no point finding the square-root at all.
Also, where you say:
+Counter is greater than distance from player
...I think it might need to be the other way around, so:
+ Distance from player is less than counter
(not sure though)
Why would it be a pain sketchy? Since there is only one player, there can easily be multiple instances of the same object/target.
Just use compare two general values to compare the values rather than just "Value x = value Y". For some reason just straight out comparing doesn't work correctly.
I think you could also use a group with the pickone event (not sure) if there are multiple objects you can target.
That's what I meant by "multiple objects of both types" - if there isn't just one player.
For example, if you are making an RTS, and want each enemy unit to follow the nearest player controlled unit, or if you are making a co-op shooter with more than 2 players.
You have to use nested fast loops, where the first loop goes through all the the "seeker" objects, and starts a second loop which goes through all the "target" objects. Like I say, it's a pain.
The "pick one" event is not good, as it only affects one instance per loop, and since it's random, some instances can get left out for longer than others. End result is that if you have a lot of objects, they can be slow to react.
It's not the same thing because when you check for the counter to be greater the counter becomes the object that is in mmf's focus instead of the specific object that is being compared to it.
In this case it shouldn't matter though because there is only one player I believe.
Originally Posted by Sketchy That's what I meant by "multiple objects of both types" - if there isn't just one player.
For example, if you are making an RTS, and want each enemy unit to follow the nearest player controlled unit, or if you are making a co-op shooter with more than 2 players.
You have to use nested fast loops, where the first loop goes through all the the "seeker" objects, and starts a second loop which goes through all the "target" objects. Like I say, it's a pain.
The "pick one" event is not good, as it only affects one instance per loop, and since it's random, some instances can get left out for longer than others. End result is that if you have a lot of objects, they can be slow to react.
Yea I know how the pick one would work. I'm pretty sure it would work fine IF there was only 1 player and multiple instances of the target. Thats what I was getting at. I dunno why I threw group in there, maybe I was on something or meant loop o_o.
The food object:
- Set Alterable Value A to distance bewtween FOOD and FISH (Clickteam movement controller EXT)
The fish object:
- Select object with the lowest Alterable Value A (Select object EXT)
- (do the events for the fish to go to the object, I do it manually with adding and subtracting 2 values as X and Y if the FOOD X/Y is lower or higher than the FISH object)