The Animationframes for my attackmotion are from frame 100 to 130. Now I need the function which applies the damage to be activated only then when the Animationframes have reached approximately frame 15 (or “half” out of these 30 frames). This attackmotion also continously loops. The problem is I can’t find any function to check which animationframe is played, so how can I implement this?
Hmmm somehow I can’t add any event…it shows me the clips are “Read-Only”. Any way to solve that?
From the Animation Outline it looks like the duration is 2 seconds exactly and the specified time would be around 1 second. I tried a dirty hack with a “timer” which activates the necessary function after 1 second after the animation was started and then sets a boolean, but this seems much uglier…
Uh what? Why do I need to create a copy of the animation in order to read (and not write) a value? This doesn’t seem logical to me, because I don’t want to edit the animation, just execute a function that is approximately at half of the clip (it doesn’t even need to be exact). Isn’t there a way to read how much of the animation has already played without using an “AddEvent” ?
E.g. I also don’t want to “hard-animate” an event but be able to change the function on the fly via variables like e.g. 0.5 for doing the function at half of the clip or 0.3 for doing it at one third. I don’t think the AddEvent is the solution to this.
Adding an AnimationEvent modifies it (remember, it saves the animation again), which is only possible with assets created in unity, not assets controlled through the import pipeline that need to be possible to reimport and update at any time.
Ah, yes that’s a good point with being reimportable/updateable at any time. Therefore this “AddEvent” is not something I want in the first place. Meanwhile I checked:
print(animation.[“bla”].length); // 2.6667seconds
print(animation.[“bla”].time); // counts from 0.0 to infinite
Some values to work with. But why does it count from 0 to infinite and doesn’t reset to 0 again once it has reached the end of the animation?
sounds like the animation is set to loop in which case the time will just go on and on and on as the animations goes on and on and on. The in-border time can be extracted through modulo
I guess the reason it doesn’t reset is that you get a discontinuity in the curve interpolation (non continous jump) which is something mathematical formulas hate like hell ![]()
Thanks, that helped me out. I still got one last question, because I have the bad feeling that this solution is “badly implemented” because it continuously assigns and calculates variables:
private var specifiedTime = 1.8;
var enable = 0;
function Update()
{
var modTime = animation["attack"].time % animation["attack"].length;
if(modTime >= specifiedTime enable == 0)
{
enable = 1;
print("hallo"); // or do function
}
if(modTime < specifiedTime)
{
enable = 0;
}
}
Is this really the only solution, or did I miss something essential here, a more “easy” or prfessional solution. I mean it works, but it looks like a dirty hack somehow with its 2 if-conditions and the variables “enable” and the “modTime” which are assigned each Update frame…?
I am also having a similar issue, I would like damage to be given to the player after the attacking animation has complete.
Is there any way to neatly do this without animation events? I have a lot of NPCs with a lot of animations, it seems dirty to have to duplicate all the animations just to add events.
Any advice would be great!
I guess its going to have to be done the ugly way.
Doing something like this by script like marctro insists on would indeed not be a very pretty setup.
Timing something with the animation really should be something the artist does while viewing the animation - which is the point of animation events. We’re aware that duplicating the source animation in order to add animation events is not idea and we are working on handling this in the background. No promises on release dates.
Hmm really? What about in my case something such as at end of animation do something
E.G
End of attack animation → do damage()
End of death animation → end game()
etc just simple, once animation has finished. Appears using lots of flags is the simplest way.
As a side note, if you wanted to copy paste imported animation to enable editing, you have to use “Menu->Edit->Duplicate” instead of Drag Drop or Ctrl+C&Ctrl+V.
It is really trivial stuff but I got stuck on this for hours. Really confusing :-p