How to make animations follow the mouse?

I’m an indie developer and I use rigged models from the web. I’m developing a split-screen game where two players throw objects at each other. The game is an FPS. I have a character model with animations - Idle, throw, jog. I created throw inside unity’s animation tool.

What do I want?

  1. I want the rig/character to dynamically move according to the mouse look (just like a human would). I need this because the other player(in splitscreen) should see a convincing animation of me looking around.
    (I cant just rotate the pelvis, each part of the upper body moves differently. The arms move the most, the head a little and the chest very little). How do I approach this in the correct way?
  2. By default the throw animation plays in forward straight direction(towards positive Z). How do I make this play when mouse is looking down or looking up, i.e. camera X axis rotation.

Multiplayer FPS’s are the perfect example, where you can see a third person view of a player.

FPS games use a mixture of rotating stuff with code and animation variations.

Mostly though they rotate the spine bone above the pelvis.

Think of this, when you throw something you throw it forward, towards where you are looking, so in the game a forward throw should be enough.

Small sidenot:
In reality you can throw sideways, but in a game you usually look at your goal, unless this is a sports game and you want to give a sideways pass, in which case you just need a: “throw-to-the–side” (pass-to-the side) animation.

No back to our problem:

The trick is to use different mouse inputs for different rotations on different bones and use ranges.

So you use the mouse.x movement to control horizontal rotation of the pelvis, but mouse.y movement to adjust spine1 (first spine bone) vertical rotation, after a certain angle (range) you want it to rotate the head. The vertical rotation to the spine1 should propagate down the hierarchy though, so when you are looking up the arms will throw upwards.

The amount of detail here is up to you, the more you add the more realistic you can make it. For instance you can rotate spine1 30 degrees, after that spine 2 is rotated too, after a few more degrees spine3 and this way you will get more detail (curved spine).

I have worked with FPS games, I have seen that a lot of them only have to spine links (bones), these are usually enough to sell the illusion. Depending on the type of game you are making though maybe more detail is needed.

I believe the way Valve does it is they have keyframes for every direction the character can look (up/down/left/right). Then they program it so when you’re looking left it interpolates the animation to the looking left keyframe, when you’re looking right it interpolates to the looking right keyframe and so on. My guess is when it can’t interpolate anymore, it rotates the character. Which is a pretty ingenious way of doing it because you can have several bones carrying out the movement and have the animator make it look natural (which could be pretty complex if you were doing it all in code).

You will want to look into blending animations. There are lots of examples where you have the character playing the walking animation while the head plays another animation at the same time (or have the bottom of the character play the walking animation while the top half plays the shooting animation).

Yes, what Jingle Fett said is true, that would be the optimum solution if you could animate and have access to other tools besides Unity, which from what I understand is not your case ( he said he animated the throw in Unity).

Thanks guys for the quick replies. My animations are very simple and as koyima said in his first post I’ll wont need much refinement.

Using Jingle Fett Valve method, I think I need only two animations:

  1. Animation from look down(-90 degrees around X axis) to look up (+90 degrees around X axis)
  2. Left and right Animation for quarter turn (90 degree turn around Y axis).

For Example, say, I have 90 keyframes for lookup/lookdown and 45 keyframes for left/right turn.
So what I do in script is:

  1. Get the current mouse.x and mouse.y and assign the right keyframe to both animations. right?
  2. At each update when the mouse moves, interpolate to the next corresponding keyframe. correct?

In Unity how do I go to a particular keyframe within the animation? If that’s possible, how do I interpolate between current and next keyframes?