I have an object (white1), with some conditions it moves to a position of another object (touch.a). but sometimes it meets an object (white2) in the same position( I mean “touch.a”).
How can I moving (white1) to (touch.b)?
(touch.b) is upon ( touch.a), And there are a lot of objects of ( touch) family, I put it horizontally, So every (white) family objects moves to ( touch.a) must go to an empty object of (touch) objects.
Any help please.
Hi kattan. Haha, that is so confusing. Is it possible for you to post a screenshot of your events and say what is the thing that’s going wrong? If you do, then smart people here (not me) will have a better chance of helping you.
I think I might understand… you want white objects to move to a touch object that does not already have another white object touching it?
If so, the thing to understand is that conditions you add to an event will restrict the instances that “exist” for the rest of the event.
So for example, if you start your event with the condition “touch not in collision with white”, then for all subsequent conditions and actions in the event after that, only touch that aren’t colliding with white are considered.
(note: to get “touch not in collision with white” , use the “touch is in collision with white” condition, but toggle the “invert condition” switch)
So, solution would be:
- “touch not in collision with white” → ignore any touch already in collision with white
- [your condition to move white is true]
- Move position of white to touch.x, touch.y
However, you may face one other problem. Since “Touch not in collision with white” includes white itself… the condition won’t work properly because its ignoring all the other whites that are already in collision with touch. Since the other whites are ignored, the condition will consider all of the touch to be free!
This is where dealing with multiple instances of the same objects can get really complicated. Try to avoid using if you can, but if you must use multiple instances there is a normal practice of using extra objects or object variables for conditions instead of the actual objects you are testing.
So for example you could add an object variable to touch called “ignore” that starts “false”. In your condition, the first time a white moves to a touch, also set variable ignore to “true”. That way, in your condition you can also include "boolean variable (of touch) ‘Ignore’ is ‘false’ " so that touches already used up will be ignored and future whites will not move to them. So, the boolean variable is used to ignore instead of the white object collision test itself.