Hi,
In this piece of code:
The instantiated objects sometimes are very close together.
Is there a way to determine the minimum distance between them in this command or action?
thanks
Hi,
In this piece of code:
The instantiated objects sometimes are very close together.
Is there a way to determine the minimum distance between them in this command or action?
thanks
Here’s a link to a post about using a collision check, or if you are any good at programming js, fast-2d-poisson-disk-sampling would be perfect,
Sorry forgot the collision post link
There is condition
Distance between two objects
You could use that to determine how close or how far away objects need to be from each other to make something happen
You can invert this condition to get distance above desired value
Since normally it works for distance below desired value
How would you use that to determine the distance between a newly created object and all the existing ones? I don’t believe it can be done the way you think, but I’m interested to see how to achieve this if it is possible.
I think OP needs to determine a potential position, check whether it’s a certain distance away from the nearest object, create the object at that position if it’s ok or select another random position and check again if not.
What we are talking about here cause i am confused?
IF we are aiming to check if objects is below or above some distance from each other then distance between two objects will do exactly that
As you see my units do not attack any buildings from the start
Because they are too far away
I think i set them to attack only if they are below 40 pixels in distance using distance between two objects condition
But as soon as i place new buildings next to them they do attack
So it is working as intended
I was pretty sure that is what OP meant
But if we are talking about checking for none existing object
Then solution to would be to move it away if it is too close on creation
Option B would be to still use distance between two positions
But in this case instead of creating objects at random position
Simply move some invisible object to random position
And simply create bat on that invisible object
And i am using exactly that to separate my units when they stop moving
Where they move away from each other until they are in some distance from each other
(im applying permanent force in random direction when distance is below something)
Option C would be to use Compare two numbers and that invisible object
But most likely it would be the same as above examples
OP wants to create a new Bat_Move object, and place it on the scene but not too close to other Bat_Move objects.
So what i wrote with invisible object would do exactly that
Just to give you clear answer and you do not need to go trough my conversation with MrMen
Create new sprite object lets call it BatSpawner
It can be 1x1 pixel in height and width
You can make it transparent image or simply hide it via events
Now you move it to random in range position you used in creation of your object so 0,500 and 0,300
Now you need event
Condition
Distance between Bat and BatSpawner is below 50 ← for example 50 you set it to whatever you need
Action
Add instant force to BatSpawner toward angle RandomInRange(-180,+180)
I would suggest force around 300 but adjust it to your needs
And now as long as BatSpawner is too close to some bat it will automatically move away from it
And now you spawn your bat at BatSpawner X and Y position
And you are pretty much set