How can this be done?

I’m trying to build a demo for a game that is like Nintendogs, where you interact with virtual animals. You pat these animated creatures, stroke their backs, etc.

Let’s say I have virtual hands, how can I have them transverse across the animals mesh? Keep in mind these animals will be animated.

For example, if I click a dogs head, the hand will move towards the head, if I drag the hand up and down, the hand will move towards those position, keeping close to the mesh and respecting the animal’s head shape

I already have the IK set up, what I need is to know:
1.) where in world space the target is
2.) hands transverse through the mesh
3.) the ideal rotation for the hands

Just to be clear, just finding the position of the target in world space is not enough, the hand needs to move across the mesh. For example, Let’s say I click a cylinder, the hand goes towards the cylinder, if I hold the click down and move my mouse, the hands will move across its surface including moving towards areas concealed from the camera

any ideas?

I just had an idea, in super mario galaxy, mario can walk across planets. I think it’s done with rigid bodies or kinematic body I’m not sure, I can turn the ik target to a physics body when I am close to the position, and use gravity to keep it on the mesh. I’m going to try this out but I’m sure there is a better solution

Indeed, you should enable physics and rigidbodies. That way, the objects cannot move inside each other.

Is there another way to do it? I don’t like using the physics system if I can avoid it as it can be buggy and expesive

Use a raycast from the hand - align the hand towards each normal on the mesh, so it’s always perpendicular.
Obviously you would avoid concave surfaces on the dog always, but they don’t have many of them!