- Home /
Clamp x,y within circle, z to sphere
Hello,
I have tried many different approaches on this, some worked but none smoothly enough.
I want a player-controlled gameobject('pointer')'s X and Y (see illustration, red) to be clamped to only move within a circle(see Actual View, green). The Z position shall be modified so the pointer always moves along a half-sphere (see Top+Side View).
Adjusting the Z position in relation to X and Y was easy using z²=radius²-x²-y².
However, I didn't find any solution that would clamp my X/Y within the circle without having my gameobject 'jump' when it approaches the limit.
The pointer is supposed to be able to be moved smoothly along the edge of the circle, but also smoothly back from the edge without getting stuck or jumping/teleporting.
Why? The player is supposed to control the rotation of an object, but since controlling the rotation directly is not handy at all, I want the object to follow a pointer. To make it as intuitive as possible, I want the pointer to move at a constant X/Y speed that ignores the depth (Z).
I have tried clamping X in relation to Y and it worked fine horizontally, though the pointer could escape the circle vertically. When I clamped both X and Y moving the pointer along the circle became jumpy.
All help is appreciated.