How to make overlapping parts push eachother away (anchored and non-collidable)

Pretty much what the title says. I’ll explain what I need it for. Basically if you break a crate or something (or even drop an item on the ground, or die and drop all your items) there will be an anchored and non collidable cylinder that will basically work as the hitbox for each item. I don’t want the player colliding with them but I want them to push eachother away in order to prevent items from piling up in one spot (think magnets pushing eachother away).

Well obviously if you just make them collidable and not-anchored they will push eachother away, but that comes with a lot of it’s own problems I just don’t know how to separate the items based on them overlapping. Basically the closer to the center it is it should be pushed harder and away in the direction it most closely is facing and only on the x and z axis I don’t want them moving up or down really at all.

I already have a crate which randomly spawns 1-4 of these cylinder on the ground in it’s vicinity. I can show that code if needed but I don’t have issues with it, I just don’t know how to make the parts calmly push each other away creating space.

What I’m thinking is if I make a code so that each cylinder will check the position of other cylinders they’re colliding with and given a direction based on the direction opposite of the colliding cylinder(s) and also a speed based on how closely they’re colliding (so if they’re directly on top of eachother they would more quickly disperse) This being said I know it’s complicated and above what I can currently do on my own which is why I’m looking for help on here.

1 Like

So I am assuming your going be using cframe to push these objects away, what your describing is similar to magnets, basically the closer a object is the stronger the force, you create multiple vectors pointing to each object nearby, and the length of that vector is representing the force, add them all up to create a resultant vector and that will be your final vector that you can add onto the object

Boids follow a similar concept if you want to read up on that

1 Like