hi,
which animation command do i use to access (get/set) the current frame?
i need to get
the “last” frame of the “throw” sequence to create the granade
and
set manually the model animation frame by frame
hi,
which animation command do i use to access (get/set) the current frame?
i need to get
the “last” frame of the “throw” sequence to create the granade
and
set manually the model animation frame by frame
Welcome to the forums!
To answer your question, you don’t ever access “the frame” of an animation that’s playing. If you want to do something like play an animation and when it’s done do something else (like create a grenade flying through the air) then look at the scripting reference entry for clip as it shows a great way of doing it. Issue the play commend then use a simple yield to wait for the animation to be done (a time based action) to trigger your next action. Easy peasy.
can you show a code sample?
if throw is animating
if throw is finished
here i create a granade
Did you follow the link I provided? If not, why not (it was provided for a reason)? If so, why was that code example not sufficient?
To help ease things I’ll copy/paste the code example from the cited page here in this thread:
animation.Play(animation.clip);
// Wait for the animation to have finished
yield WaitForSeconds (animation.clip.length);
All you have to do is insert the right animation clip to play (your “throw” animation) and then after the yield, do what you need to do (spawn the grenade for example).
If so, why was that code example not sufficient?
this is not a “code sample” or a “sample script” this is a command syntax.
Sure thing. What ever you want to call it it has some example code you can look at and expand upon. You still haven’t pointed out anything about what’s insufficient about what I’ve offered so I’m not sure where you’re stuck.
ok
i´m looking the character animation script samples.
1 more doubt:
how to adjust the crossfade smooth transition range value?
because depending on the animation i want to Slow down or speed up the transition
I think what you’re after is Animation.CrossFade as it allows you to cross-fade between the current animation and one you want to specify, and you provide the time over which to do that.
animation.CrossFade(“Walk”, 0.2);
thanks.
To answer your question, you don’t ever access “the frame” of an animation that’s playing
and how can i create frame based actions?
one example,i need the right frame to create foot steps with precision and not the time.
You can get the frame of the animation easily enough with the time value, you just have to calculate it yourself, provided you know either the total number of frames in the animation or the framerate of the animation. AFAIK every animation in Unity has a fixed framerate it plays at independent of the player framerate. You can find this out in the 3D program used to create the animation, or if you created them procedurally in Unity you would be able to find this out from the script used to create them.
If you have the total number of frames, you can figure out the frame an animation is at with this formula:
(time * speed / length) * totalFrames
Or if you have the framerate, with this formula:
(time * speed) * framerate
That will give you the approximate frame the animation is on (approximate since the result will probably be a float, while frames are better represented as ints).
thanks i will try!
but
in editor can i pass through the character frames
and STOP in the exactly frame where i want to:
get the right position for instantiate and adjust the grenade in the last frame?
or
position and adjust(move,rotate,scale) a weapon (axe) in the first frame?
I take it you’re animating a rig, right? If that’s the case, then you just need the right frame. Take the frame you want in the 3D editor and divide it by the frames per second to get the point in time after the animation has begun.
So, using that time, you could call a function that waits for just that long and does whatever you need.
Edit: Position is a little more work, but you can just find the relative position by using the editor like you said. Once you have that position, just write it down and put an empty there to mark it.
Another approach might be to use;
Brilliant, Charles! You cut to the root of the problem, I think. If all you need to do is perform an action at a specific point in the animation, create a function that performs that action and add it to your animation clip as an AnimationEvent.
Hello, I’m new to Unity and as good as to programming. I’m a junior game designer doing 2d and 3d and design. And trying to make some of my 3d scenes interactive using Unity.
Currently I’m following the Lerpz 3D Platform tutorial.
How does the animation script know which frames are the Run animation and which are the Jump anims?
Inside the script I don’t see “frame 15 - 25” or something like that. And with the exporter in 3DSMax I can’t give names to certain frames.
I got the animations to work in the tutorial but can’t find how the script is linked to the imported FBX.
It’s probably a simple question but any help would be greatly appreciated.
In Unity’s import settings you can tell it which frames to split into different clips and what to name each clip. Unity then automatically creates different AnimationClips based on your settings and assigns them to your model’s Animation component.
Click on the Lerps animation and then find the menu option “Import Assets”. There you will see the settings for how that asset should be imported, and from there you can configure things like;
“Walk” = Frames 1-25
“Jump” = Frames 26-50
…and so on.
Afterwards, you can then code animation.Play(“Walk”).
Edit: Position is a little more work, but you can just find the relative position by using the editor like you said. Once you have that position, just write it down and put an empty there to mark it.
hi,thanks!
like i said not.as I asked!
can i play/pause the character animation frame by frame(NOT time)in time line?
because in animation docs I’m seeing just the time/seconds in time line.
i want to see “the frame” = maya time line.
can i play/pause the character animation frame by frame(NOT time)in time line?
I asked about handling animations on a frame-to-frame basis myself a little while back here: http://forum.unity3d.com/viewtopic.php?t=18732&highlight=
PirateNinjaAlliance said: Most 3D game engines (unity included) are simply interpreting animation curves in a time-based manner - they have no concept of your animation in terms of frames or poses, and there’s no built-in setting to achieve that effect at the moment.
Though using AddClip, in script or on import into the editor, to single out frames in the animation should give you the control you want over event handling and playback speed for specific parts.
Most 3D game engines (unity included) are simply interpreting animation curves in a time-based manner - they have no concept of your animation in terms of frames
Most 3d game engines?
i can get/set current frame in any game engine.
these are “the basic” animation commands,when i can´t find in unity docs I found it very strange!
none animator are interested in time!
any animator are interested in frames!
that is why any animator can see the key frame in
maya/max/xsi/milkshape… time line.
i´m evaluating unity and i want just port my old dbpro,blitz3d,3dgs games and I do not believe that I can not do it the same with unity.
please some animator(UT animator) can explain how?
because until now I do not understand!