I need to find the distance one entity overlaps another so I can move the first away from the second by that amount. I remember seeing things to do this, I just can;t seem to find the posts/tutorials.

I’ve tried something like `partA.getposition() - partB.getposition();`

but this doesn’t seem to work.

```
function distanceBetween(entityA, entityB) {
var posA = entityA.getPosition();
var posB = entityB.getPosition();
var dx = posB.x - posA.x;
var dy = posB.y - posA.y;
var dz = posB.z - posA.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
var dist = distanceBetween(entityA, entityB);
```

2 Likes

Right, I thought there was more to do than I had, thanks!

EDIT: I just realized this will move the object linearly out of the other by the shortest route. Is there a way to make it angular so I can rotate the object away from the other on one axis? (should have mentioned this in my first post, sorry)

Here’s a link to my project to help get an idea of what I’m trying: https://playcanvas.com/editor/scene/593817