The Daily Click ::. Forums ::. Klik Coding Help ::. Spread Value problem
 

Post Reply  Post Oekaki 
 

Posted By Message

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1968

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
15th June, 2010 at 15:22:24 -

It's a lot easier if you prevent the enemies from ever overlapping in the first place, rather than trying to separate them after. As part of their movement system, you should check that there isn't another object already in their path.

When you want to compare values from two instances of the same object, you usually need to store a value in an intermediate (eg. a counter).

eg. If you wanted to check if any two instances of "Object" are within 100 pixels of one another...

+ Always
-> Spread value 0 in ID("Object")

+ Always
-> Start Fastloop "Check1", NObjects("Object")

+ On Loop "Check1"
-> Start Fastloop "Check2", NObjects("Object")

+ On Loop "Check2"
+ ID("Object") = LoopIndex("Check1")
-> Set XCounter to X("Object")
-> Set YCounter to Y("Object")

+ On Loop "Check2"
+ ID("Object") = LoopIndex("Check2")
-> Set Distance("Object") to Sqr(((XCounter - X("Object")) pow 2) + ((YCounter - Y("Object")) pow 2))

+ On Loop "Check2"
+ ID("Object") = LoopIndex("Check2")
+ Distance("Object") < 100
-> the object whose ID = LoopIndex("Check1") is within 100 pixels of the one whose ID = LoopIndex("Check2")


Again though, it's very rare that you actually need to do any of this - there's usually a better way to achieve the same overall effect.

 
n/a

superpower



Registered
  07/06/2010
Points
  27
17th June, 2010 at 07:25:01 -


Originally Posted by Sketchy

+ On Loop "Check2"
+ ID("Object") = LoopIndex("Check2")
+ Distance("Object") < 100
-> the object whose ID = LoopIndex("Check1") is within 100 pixels of the one whose ID = LoopIndex("Check2")




Isn't "the object whose ID = LoopIndex("Check1") is within 100 pixels of the one whose ID = LoopIndex("Check2")" supposed to be a condition and not an event!?
And if not, could you explain what is going on?

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1968

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
17th June, 2010 at 11:24:58 -

No, I just meant that if the other three conditions are true, then you know which two objects are within 100 pixels of each other - you'd insert you own action depending on what you wanted to happen.

 
n/a

superpower



Registered
  07/06/2010
Points
  27
18th June, 2010 at 12:11:12 -


Originally Posted by Sketchy
No, I just meant that if the other three conditions are true, then you know which two objects are within 100 pixels of each other - you'd insert you own action depending on what you wanted to happen.



I still can't get it to work, darn it! "Distance" is an alterable value right? Do I need multiple counters!?
The distance formula I used looks like this:
Sqr(((value( "XCounter" )-X( "Enemy Test" )) pow 2)+((value( "YCounter" )-Y( "Enemy Test" )) pow 2))

For some reason it runs the action (where the enemy is supposed to move over) all the time even though his value is more than 100.
I did the last conditions you mentioned exactly the way it's supposed to be.

Hmmm... Seems like one guys "distance" is always set to 0 for some reason. I think that with this set up the other enemies are comparing they're distance to the enemy who's distance is 0.



The comment overhead is obsolete (I'll leave it there just for laughs though) since:
Duhhh. I just realized that you didn't mean "counter" by "counter". Uhhh... I've probably suffered a serious burnout or something

Man.... What an EPIC fail!

I must say though. The effect of my frankly "best laugh ever"-fail was interesting to say the least

Edited by superpower

 
n/a

superpower



Registered
  07/06/2010
Points
  27
18th June, 2010 at 14:31:08 -

If I remove the "Set XCounter to X position"-event the distance becomes the objects x position in the frame. However, if I use the event the distance is always set to 0. Any ideas?

 
n/a

superpower



Registered
  07/06/2010
Points
  27
18th June, 2010 at 14:43:18 -

I'm so close to giving up on this game and the entire program. How hard can it be to make it so that two bad guys won't overlap each other and still follow the player around?
My game works like this.
When a hitbox hits the enemy, he starts chasing the player.
Depending on which side of the player he is, his moving value will change to either positive or negative.
When his moving value is -1 he will move left from his own position 5px every 0,03 seconds and vice versa.

How would you make it so that the enemy can't overlap another instance of itself?

Stuff like this doesn't work:
When enemy is overlapping enemy change moving to 0.
Since the enemies will then get trapped in an eternal "overlapping" cycle.

Any ideas will be appreciated...

Edited by superpower

 
n/a
   

Post Reply



 



Advertisement

Worth A Click