Having models 'repel' each other

I’m trying to make item drops in my game ‘repel’ each other (sort of like magnets). They’re anchored and non collidable so I think I’ll have to check for collisions myself using rays.
My main concern is performance because there could be an instance where 20 of these items are all dropped at once (with a wait()) on the same spot and I don’t want it to cause lag in my game.
Is there a good lag-free solution here? Or should I just forget about it and just place them on a grid or something.

i think you can use the SpringConstraint,
you can weld a Sphere Part as hitbox to an item which is the max radius of the spring,
on Touched, attach sprint constraint to those parts, and when TouchEnded, remove that spring

Sounds promising, but the items are anchored and floating a little above the ground. I guess I could have ‘ghost’ parts that figure out where to go and give them their own collision group and the items just repeatedly update to their positions, thoughts?

then i think i may still use the hitbox spheres just to register which of them are close to each other,
then for each of those bulks, calculate their repel forces and move in PreSimulation or Heartbeat

You would need to code the physics yourself.

It’s not hard so here is a breakdown:

  • Assign velocity to each pickup.
  • In a heartbeat loop, add the velocity of the pickup to its position times the delta time returned by the heartbeat loop. Then set the velocity to zero.
  • Check for all close by pickups in a specified radius.
  • If there are any close by pickups then add this formula to the velocity: current_pickupPosition - nearby_pickupPosition.
  • Done.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.