I would recommend Blender rigging tutorials by "Level Pixel Level" on YouTube. He's the one who made it clear to me that there can be several layers of rigs to create the motion and control that you desire. A basic layered rig setup would be:
- Mesh object - gets deformed by the deform rig.
- Deform rig - armature that does the mesh deforming. Sometimes very complex and it needs to be controlled by the:
- Control rig - armature that is meant to be used by animators. As simple as possible.
In your case, I imagine that your deform rig bones need a limit. You might even build a control rig bone or two if you want to make controlling the deform bones easier, but first things first.
Limits can be set for bones in many different ways including:
- Placing bones in key areas, sizes, rotations
- Parent and child relationships
- Bone constraints (which are NOT the same as regular constraints. Set these in bone pose mode or bone edit mode.)
- Layering one rig on other rigs for multiple driver and constraint functionality. Advanced riggers love building these. It scares some of us. The reward is a flexible rig that is easy for animators.
Some bone constraints you may want to try:
- Shrinkwrap - Target Normal Project - On Surface - Align Axis to Normal (Personally, I think you might be able to do what you want with this one alone.)
- Limit Distance>Clamp Region Outside
- Limit Rotation
- Limit Location
The principles that really help are keeping it as simple as possible, and finding the right mix that works for your particular situation. I stacked a few modifiers like so to push my shrink-wrapped pupil above the sphere. Plus I would only need to rig a few points on a 2D cirlce instead of a 3D shape. The Solidify modifier makes it 3D for me after the fact:
You can also make your bones rotate from the center of the head so they are less likely to push the eye under:
Update Thanks for the blend. I did some adjustments to the left eye and have uploaded the file here. Changes list:
- Turned off Shrinkwrap modifier for the eye mesh. I don't think you need it at all! Moved eye mesh closer to head in Edit Mode and reshaped it smoother with proportional edit. (it had a dent up top). Smoothed vertices by selecting all and Alt+O a few times. Topology that is smooth and clean makes for better deform animation.
- Adjusted eye bone positions by adding shrinkwrap bone modifier to them all and then Pose mode: Ctrl+A "Apply Pose as Rest Pose". This fixed the ugly eye mesh deformations due to the new bone shrinkwrap positions. Use the Shrinkwrap settings in the screenshot below to get the bones to point according to the head mesh normals. Also, see below how to easily copy a bone constraint to multiple bones:
An easy way to add the same kind of bone modifier to other bones is to set the first bone modifier, then in Pose Mode select all bones you want to paste it to, and finally select the bone that has the modifier you want to copy and press F3 "Pose: Copy Constraints to Selected Bones".
- Made a bone in center of eye as a parent controller for looking around. It is also shrinkwrapped so you can move the eye around the entire head without it going through the mesh: