The Daily Click ::. Forums ::. Klik Coding Help ::. Take object that is nearest /
 

Post Reply  Post Oekaki 
 

Posted By Message

Solgryn

Solgryn dot org

Registered
  20/12/2008
Points
  12572

GOTW Winner!VIP MemberWii OwnerIt's-a me, Mario!The Cake is a LieGOTM 2ND PLACE! - APRIL 2009GOTM 2ND PLACE - JUNE 2009PS3 OwnerKlikCast #15 Compo Winner!LOL Sign
You've Been Circy'd!GOTM WINNER - JANUARY 2010I am an April FoolGOTW MARCH 2010 WINNER!Santa Hat
19th July, 2009 at 15:56:09 -

How do I do this?

It's like when I have an AI and I set it to go to an object, it always takes the newest object.
Don't know excactly how I do this, please help =.

 
www.Solgryn.org

Image

Ski

TDC is my stress ball

Registered
  13/03/2005
Points
  10130

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!KlikCast HelperVIP MemberWii OwnerStrawberryPicture Me This Round 28 Winner!PS3 OwnerI am an April Fool
Candy Cane
19th July, 2009 at 16:31:43 -

Take object that is nearest or newest?

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3334

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
19th July, 2009 at 16:50:54 -

Well, I've never tried this, but you could.

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.

Edited by OMC

 

  		
  		

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th July, 2009 at 18:13:43 -

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)


Edited by Sketchy

 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
19th July, 2009 at 18:46:06 -

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.


 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th July, 2009 at 19:07:17 -

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.

Edited by Sketchy

 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3334

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
19th July, 2009 at 19:24:08 -

I think I stuck that Absolute value in there because I saw one of our resident math geniusi use it with the distance formula. Silly me.


Originally Posted by Sketchy

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)



Is this not the same thing? O_o

Edited by OMC

 

  		
  		

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  50177

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
19th July, 2009 at 19:38:08 -

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.

 
n/a

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
19th July, 2009 at 21:04:12 -


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.

Edited by GamesterXIII

 
n/a

Solgryn

Solgryn dot org

Registered
  20/12/2008
Points
  12572

GOTW Winner!VIP MemberWii OwnerIt's-a me, Mario!The Cake is a LieGOTM 2ND PLACE! - APRIL 2009GOTM 2ND PLACE - JUNE 2009PS3 OwnerKlikCast #15 Compo Winner!LOL Sign
You've Been Circy'd!GOTM WINNER - JANUARY 2010I am an April FoolGOTW MARCH 2010 WINNER!Santa Hat
19th July, 2009 at 21:14:11 -

Are there someone who could make an example? That would be great.

And I mean I have for example 2 fishes and 5 foods. The fishies need to go to the food that is near to them.

 
www.Solgryn.org

Image

Solgryn

Solgryn dot org

Registered
  20/12/2008
Points
  12572

GOTW Winner!VIP MemberWii OwnerIt's-a me, Mario!The Cake is a LieGOTM 2ND PLACE! - APRIL 2009GOTM 2ND PLACE - JUNE 2009PS3 OwnerKlikCast #15 Compo Winner!LOL Sign
You've Been Circy'd!GOTM WINNER - JANUARY 2010I am an April FoolGOTW MARCH 2010 WINNER!Santa Hat
19th July, 2009 at 21:27:45 -

I got it working, nice and simple way:

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)


Nice and easy no need for fastloop stuff =


 
www.Solgryn.org

Image

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th July, 2009 at 21:41:57 -

Ahhh, so someone has converted the "value finder" extension (or at least soem of it's functionality) - they just renamed it!

I made an example anyway, so maybe someone will find it useful - it handles multiple instances of the "predator" and "prey" objects:

http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/Seeker.mfa



Edited by Sketchy

 
n/a
   

Post Reply



 



Advertisement

Worth A Click