Playing animation frame by frame by procedural controller

Hi guys,

I have read the post regarding "Freezing an animation on a certain frame" as a reference for something Ill be trying to do...

Im wondering if it is possible to play an animation frame by frame by a procedural control?

The idea would be to use this for the characters aim.

I have the character animated in a 3D package (Maya/Max/Whatever) wich would be aiming straight downwards, straight ahead and aiming upwards.

Is it possible to have the animation set and paused at a certain frame depending on the characters aim angle? So if it aims at max limit upwards the animation would be set and paused at the last frame of the sequence, wich would be aiming up, as character points aim downwards, the actual animation frame played and displayed would be that corresponding one till he reaches the straight aim, then aiming downwards and so forth.

Has anyone tried anything similar? Would be this the best way or would anyone happen to know a better way to make character aim procedurally?

Im sure this would be something quite common to be implemented in games...

Oh, and I forgot to mention that this would be set at LateUpdate()...

If someoneo could help out! :D

Thx in advance! :D

This is very much possible. By directly controlling the time of the animation you could have, say, time=0 be aiming down, time=1 aiming straight ahead and time=2 straight up. Then by using AnimationState you can manually set the time, and thus the animation to display.

Ok guys,

It works!

Just to clarify some things to others that might try this approach:

As mentioned, I used a character animated aiming up and aiming down, the straight aim is the default pose wich would be frame 0. So the animations go (as an example) from 0 - aiming straight ahead, 90 - aiming 90 degrees up, 100 aiming straight ahead again to 190 aiming 90 degrees downwards.

Use your mouselook script to get the direction player is aiming in the x axis. in my case, Im using full 90 degrees for aiming upwards and -90 degrees for aiming downwards.

(I noticed most games dont go that far, like Counter-Strike, Battlefield etc., if you watch the character even if he aims straight up the character pose in game has a limit of about 60-70 degrees)

So in unity, have your animations for aiming up and down split or seperate, set their blendmode to additive and finally set the animation time (wich would be our desired frame/pose for the corresponding angle of aiming) in seconds, since our framerate is set to 30 FPS for animation in the 3D package (maya/max/whatever), for 0 to 90 frames of animation we have 0 to 3 seconds, wich is what unity uses.

something simple like: animation["AimUp"].time = camera.aim_x /30;

So this is the way I got it working! :D

Thanks again guys!

Cheers!:D

Hey man!

I'm trying to use your approach for my 3rd person shooter game. I'm running into some complications though. My character is shaking up and down while aiming with his hands. Did this happen for you? Could it be that i'm in between two different frames? Thanks in advance!

Hey,
in “animation[“AimUp”].time = camera.aim_x /30;”
is “camera.aim_x” in your mouse look script?
im relatively new to scripting, can you explain the way you do this just a little more?
thanks

Well if you want to do that in Animator then use this

Lets say you want to play the animation from the mid frame .This is how u will do it

getComponent().Play(“Animation_Name”,0,0.5f);

or

getComponent().Play(“Animation_Name”, 0 , (1/total_frames)*frame_number);

For more you can refer here