How do I make actors move to a random position without overlapping?
lollipoppy811228
Member Posts: 5
I'm trying to create a scene where 6 actors are gathered in the center and then scatters to random positions after 1 second without overlapping the original positions and each other.
I've figured out the timer part.
but I'm confused about the position part.
I've used change attribute - self.position.x to random
but how can I make them not overlap their original position?
Please help
Comments
One technique is to move the actor to a new random position if it overlaps or touches another actor. You can use actor tags to simplify the rule if desired.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you for the comment!
I've made a rule with a collision condition and the random position behavious under the rule as you said.
but it seems not working as it should be.
Is there a way to repeat the repositioning part until they don't overlap?
You may need to place the overlap rule inside an every 0 seconds Timer. Theoretically, it should work without one but when I tested it (as you did), it required a timer/loop.
When you set the actors' positions, add/subtract half of their size:
Change attribute self.Position.X to random(0+self.Size.Width/2, 568-self.Size.Width/2)
The 568 represents the scene width. You'll need to do the same with the Y position, adding/subtracting half the height of the actor from the scene height.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you! It helped a lot!