Distance between camera and object

I don’t want to people to click a key far away from it so they don’t cheat how do I make it so you have to be close to the key in order to pick it up?

Hi @Sebastian_Santos,

You can add “If distance between camera and key is less then *” check into "When clicked " CoBlock


Hope that helps


Can someone help me code that in scripting?

let dog = Scene.getItem("udoXYGIy") as AnimatedItem;
let cat = Scene.getItem("XCjfsFRN") as AnimatedItem;

let distance = cat.center.dist(dog.center);

I’m sure you can work out the rest :wink:

Note that this is 3D, not distance on the XY plane.

Have fun!


1 Like