Attaching an object based on proximity

I am having trouble figuring out how to make an object attach to another object if they are near the player.

Example:

Theres the Player Object, Object A, and Object B.

There are 2 Object A’s near the Player Object. Whichever Object A is closest to the player will attach Object B to it.

3 Likes

Well, you could extract both object’s coordinates and subtract them from the player’s one, then make it absolute value to see which one is the closest

Thank you, ok, I will try that.

Wait, how would that work. I am very confused.

Ok so, make a trigger, when its triggered, send a message to the Object A’s, in the ObjectA behaviour, once they get the message, they extract their own x coordinates and subtract it from the Player’s x coordinate(via global) in a expression, using the absolute value(make all numbers positive) number that comes out of the expression, you will be able to determine which one is closer(which one has the least amount of distance from the player) and therefore find it… but now that I think of it, I have no idea how to find absolute value OR sort the A’s to find which one is closer, but I’m sure there’s a way :sweat_smile:

2 Likes

Time to call in the big guns. @JR01

2 Likes

nevermind (20 characters x 40)

I just made this… hope it works!!!

2 Likes

Thank you for trying but this isn’t what I was asking about. :slight_smile:

how bout increasing the proximity distance rapidly, when you find object A, stop and use a messaging block to send to last proximitied object to attach? not sure if this would work

2 Likes