The Daily Click ::. Forums ::. Klik Coding Help ::. Distance Between Objects
 

Post Reply  Post Oekaki 
 

Posted By Message

mastavasta



Registered
  27/07/2010
Points
  113
15th December, 2011 at 21:14:49 -

I have an active object(Active1) and a group of objects(Group.Good). I need Active1's alterable value to equal this:

The distance between Active1 and the closest object of Group.Good

As of now, I just have the variable set to the distance between Active1 and Group.Good. It works perfectly when there is only one object in Group.Good, but whit 2 or more objects, it fails. By "Fails," I mean that half of the Active1 objects will pay attention to a one Group.Good object, while the other half pay attention to another Group.Good object.

This is what I have so far:

+Start of Frame
-Spread 0 to Alterable Value A of Group.Good
-Start Fastloop "test" (Number of Group.Good Objects times)

+On Loop "test"
+Alterable Value A of Group.Good = LoopIndex of "test"
+(Code for distance) !=(does not equal) Alterable Value A of Active1
-Set Alterable Value A of Active1 to (code for distance)

Any help would be much appreciated!

 
Go into my head, then come back out and tell me I'm wrong.

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
15th December, 2011 at 22:35:03 -

It's no good just checking whether the distance does not equal the previously stored value - to get the nearest object you would need to check if it is less than the previously stored value.
This means you would also need to set Alterable Value A to some huge number (must be higher than the longest possible distance to the nearest group.good) before you start.
Also, because of the way object selection works, you would have to check whether the Alterable Value A of Active1 is greater than the distance - not whether the distance is less than the Alterable Value A of Active1 (using "compare two general values" messes up object selection).

So, here's exactly what you need to say:
(pay close attention to the order in which everything is written)

+ Start of frame
-> Group.Good: Spread value 0 in Alterable Value A
-> Active1: Set Alterable Value A to 99999999
-> Start fastloop "test", NObjects("Group.Good") times

+ On loop "test"
+ Group.Good: Alterable Value A = LoopIndex("test")
+ Active1: Alterable Value A > (code for distance)
-> Active1: Set Alterable Value A to (code for distance)

 
n/a
   

Post Reply



 



Advertisement

Worth A Click