# Implementing attraction-repulsion with cannonjs

**URL:** https://discourse.threejs.org/t/implementing-attraction-repulsion-with-cannonjs/14258
**Category:** Questions
**Tags:** animation, cannonjs
**Created:** [April 11, 2020, 10:20am UTC](https://discourse.threejs.org/t/implementing-attraction-repulsion-with-cannonjs/14258 "2020-04-11T10:20:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ac70](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ac70/32/8339_2.png) [@ac70](https://discourse.threejs.org/u/ac70)
#### Post date: [April 11, 2020, 10:20am UTC](https://discourse.threejs.org/t/implementing-attraction-repulsion-with-cannonjs/14258/1 "2020-04-11T10:20:20Z")

</div>

Hello, I’m trying to understand what is the right way to implement a system of attraction-repulsion between two spheres by using cannonjs.

I should basically be able to determine two forces which regulate the following rules:

- if the attractive force = repulsive force: the two spheres stay in equilibrium and don’t move.
- if the attractive force \> repulsive force: the spheres collapse into each other.
- if the attractive force \< repulsive force: the spheres get away from each other.

I saw [this thread](https://github.com/schteppe/cannon.js/issues/362) but I didn’t understand how the force is implemented in this scenario.

EDIT: I have used Spring but it only works with two spheres. You can download my demo: [cannonjs-attraction-repulsion.zip](https://discourse.threejs.org/uploads/short-url/lBvzKfKkdwFv4ldfRw1oUUFQzm6.zip) (1.4 MB)

**Is there another way?**
