Limit Vector Size in a radius

Hello,

I’m making an object which the player controls it by adding relative location.

What a want to do: When this object arrive some distance (length between Character and the object), they will not be possible to go any further, just to return, and keep in that radius without going away.

How can I do that?

Thanks!

Hi,

Just need clarification on something. Are you trying to keep the object within some distance of the character? Or are you trying to keep the character within some distance of the object?

If you want to keep something within a certain radius of something else, you can try doing this. Say we want to keep “B”, within some distance “r”, of “A”.

  1. Get the vector, let’s call it “U”, from the A to the location where you are trying to move B.
  2. Get the size(length) of U and check to see if it’s greater than r.
  3. If it is greater than r, don’t move B in that direction.
  4. If B somehow ends up outside of the radius, just normalize U, then multiply it by r. Set this vector as B’s relative location from A.

This is also assumes that B is also attached to A. That way B moves with A.

Can you try using a > node instead of a >= node?

Hi RoboScorpion, thanks for the repply.

Yes, the object is attached to the player, and will keep in the radius of the player.

I tried what you said, but when I set the relative location of the step 4, it reset the location to 0 when reach outside the radius.

Take a look if I’m doing something wrong:

Yep. Same results.

Math your vector and clamp it after all.

Hello Two-faced, thanks for the repply.

I clamp the vector between A and B, but don’t figure out how I use with the add relative location node

Add location manually with + node)

Sorry, I don’t get it :frowning:

You should get location, + it, clamp and set.