How to limit the position of an object within a circle?


How to limit the position of an object within a circle?

I was trying to use some mathematical formulas, but is giving error.

(posx ²) + (posy ²) = (radius²)


maximum position of posx ² should be (radius ²) - (posy ²)


maximum position posy ² should be (radius ²) - (posx ²)

I am using Float Limit in X and Y position, with Float Script in each.

for example,

R = 50

If the value of x is equal to 15, the maximum value of y can only be 35.

If the value of y is equal to 25, the maximum value of x can only be 25.

ERROR: Circular Dependency


As far as I’ve tested,the limit controller is only good for lineal limits, I tried long ago to use math for a radial limit with this ‘float limit controller’, and it failed not because of circular dependecy, but because it gets the values without a consistent order(x,y,z), and the result was that it shaked a lot. but I think, I gonna try again…


why are you trying to limit both axes, though?

If you limit one axis, you automagically limit the other.

I.e. if the radius is 100 units, and you limit the X axis to -100 … 100.
And you limit the Y axis to -(sqrt(100^2 - xPos^2)) … (sqrt(100^2 - xPos^2))

Then at xPos = 100, yPos will be zero.
at xPos = 50, yPos will be 86.6025.
conversely, if you were to try to set the yPos to 86.6025, that position is only ever valid for an xPos = 50.

This presumes you meant limiting the position within that circle as far as user interaction goes.
Attached file is 3ds Max 2008 - if you need one for r8 / r9, I can re-create it. But it’s essentially just putting the equations above into the appropriate limits.

If you have scripts that interact with yPos, then that script will have to calculate the appropriate xPos itself. Otherwise you do indeed get a circular dependency (at least with this construction)


Here’s another solution, that uses a target node and a normalized vector to produce a slightly more flexible result in the viewports.

If you wanted to constrain to the circle’s perimeter, rather that the area, you would just use the second line in the the position script.

It also works in 3 dimensions. If you wanted to limit it to 2, just multiply the final result by [0,0,1] (or your chosen axis)



It was therefore much more easily than I was doing.
But because that sphera has a kind of snap in posx?

Only failed to use the Freeze Transform in sphera, because without it when I make a link in the circle of sphera, he is confused when I move the circle after the link.



I had already tried with the Taper, but only restricting its Length.

Thanks also!


It ‘appears’ to snap to X because moving the sphere in X will limit Y, while moving in Y does not directly (only inherently) limit X. So when you move the sphere outside of the circle (the radius), any values of X < -radius and X > radius will cause the Y value to be zero, regardless of the Y position you’re trying to set it to.

Davesterwart’s method is much more flexible and doesn’t have this apparent ‘snapping’ behavior, but does require that you tell the user to manipulate a node other than the node you’re actually limiting. There might be a way around that, as well - not too sure :slight_smile:


Yeah - it would be cool. It’s the sort of thing you could waste hours on trying though!



Can I get the scene compiled for max9 please? I am very interested in your solution.



You could just use an HI IK chain on a couple of bones + nub, each bone length 1/2 radius. The nub is constrained to the sphere, (or circle, if you lock the goal in Z)


doh, dont work on max 8.

Any chance of a quick overview on how you have set this up?


which method are you going for?


not sure. Im looking to limit to a box. Are you just using a limit controller?


…the simplest way to consttrain to a box would be limit controllers, IMO. Put a parent dummy at the center of your (real or imaginary) box. Link the constrained object to it. Put a limit controller on each position axis of the constrained object, plus and minus half the dimension of the box, in the respective axis.


Hey Guys,

Very interesting thread.

Any chance of getting Dave Stewart’s solution (target node and a normalized vector) in a Max 9 compatible file? If not, could someone please elaborate on that approach? I’m happy to give it a try but I’m not quite sure where to begin.

Thank you very much as always.

  • Dave


See attached

Essentially the setup (slightly different from Dave’s, but only in terms of variables- i.e. the center can be moved) is that there is a script controller on the box that has 3 variables:

  • center - assigned to the position track of the circle
  • radius - assigned to the radius track of the circle
  • target - assigned to the position track of the group (tape end + text)

It then checks if the distance between the center and the target is less than the circle’s radius… if it is, then the target is inside the circle, and the target’s position is used for the box’s position ‘as is’.
If it’s -more- than the circle’s radius, then it calculates a new position relative to the center, in the direction (vector) of the target position (by taking the target position relative to the center), of at most radius distance away (by normalizing the vector, then multiplying by radius).

It actually makes more sense when you look at the file :wink:


Hey Richard,

Thank you for the reply and for taking the time to get me the Max file. That’s a pretty awesome approach… it feels really good in the viewport and I love how the radius is adjustable.

Where I see it differing from what I was hoping for is how the moved object “move me” can be moved outside the circle. I would like an animation control that gives the animator feedback as to where the limits are on the actual control. To do that would I just use the other method you described? - i.e. A limit controller with one axis using the expression: -(sqrt(100^2 - xPos^2)) … (sqrt(100^2 - xPos^2))

I did get that to work successfully but the “snapping” feel you get on the one axis (which I understand the reason for) is somewhat less than desirable. Is there a way to soften that affect?

Thanks again, your help is truly appreciated.

  • Dave


hey heyitsdave…this is my approach click (max 2009)
with this you can drag the actual controller, and it limited by the circle .
but, i got some error:
turn ON auto key
select circle controller,then move the time slider
booom…keyframe suddenly appear in every frame, even you don’t animate the joystick
i don’t why this could happen…
anybody can help me?


sorry for bouncing…
anyone can help me…i’m waiting for answer…


Honestly your setup is very dirty. But if you want just to fix the “keying” problem change “Scale” script to:

radius = $Circle03.radius - 8
pos = target.pos
with animate off
if ((distance center pos) > radius) then target.pos = (
 center + ((normalize (center - pos)) * -radius)
else ( target.pos = controller )
[1, 1, 1]


thanks DenisT…it’s works…:applause:
but, i dont know what you mean about “dirty setup”
what the “dirty” thing is?
I’m still learning a lot become a technical artist (rigging)
your advice might very useful for me…thanks