Surzie

Hi,

New to the forum, to Unity, and C#. Really, new to everything. I started my coding journey just about a year ago. So I ask your forgiveness if I am asking something simple or that has already been solved (although I have looked through all the posts and found nothing which prompted me to make an account!).

So, just some context for what my problem revolves around. I am creating a hero for a game where the rate of his attacks can be adjusted dynamically through items or "buffs". I am using TrackEntry to change the animation state on a track other than "0" in the update function or when another function is called:
var attackTrack = characterSkeleton.AnimationState.SetAnimation(1, Attack1, false);
attackTrack.EventThreshold = 1f;
attackTrack.AttachmentThreshold = 1f;
attackTrack.MixDuration = 0f;
var empty1 = characterSkeleton.state.AddEmptyAnimation(1, 3f, 0.1f);
empty1.EventThreshold = 1f;
empty1.AttachmentThreshold = 1f;
I have encountered two problems arising based off of my mechanic of "rate of attack":
    1.If the rate of attack is fast enough, the animation is clipped, and restarts the attack animation
    2. The events which I have on the animations do not fire if the rate of attack is fast enough.

I have found if I change the Time Scale of the animations, I achieve what I want, the animation plays to completion AND the events fire.

The problem with that though is that the attack animations Rate of Attack changes dynamically and constantly and a constant time scale of 3 looks really wonky. Is there a way around this? Is there something im missing? Do I have to just suck it up and do SetAnimation(1, Attack1, false).Timescale = x; and do some crazy math that changes "x" based on an inverse relationship of Rate of Attack somehow?

My intended outcome is to have my animation of the attack play in full based on the rate of attack and raise the Event (Damage) that is on the animation. If the rate of attack is 1.5 seconds, then I want the animation to occur once every 1.5 seconds. Same goes if it is 0.5 seconds, I want the animation to occur once every 0.5 seconds.

I am sorry if this is a little confusing, I will clarify anything that I can or add anything that is needed. Please help! Anything is welcome!
Surzie
  • Postovi: 5

Harald

Hi and welcome to Spine! 8)
Surzie je napisao/la:1.If the rate of attack is fast enough, the animation is clipped, and restarts the attack animation
Could you please describe in more detail what you mean by "clipped"? Do you mean the previous animation is ending too abruptly? If so, please note that your line attackTrack.MixDuration = 0f; sets the transition duration to 0 seconds.
Surzie je napisao/la:2. The events which I have on the animations do not fire if the rate of attack is fast enough.
Are the events located before the timepoint at which you abort your attack animation and start the next one? Please note that if they occur after you transition to another animation (and the transition is finished since you used AttachmentThreshold = 1f;), they won't be issued.
Avatar
Harald

Harri
  • Postovi: 4104

Surzie

Harald je napisao/la:Could you please describe in more detail what you mean by "clipped"? Do you mean the previous animation is ending too abruptly? If so, please note that your line attackTrack.MixDuration = 0f; sets the transition duration to 0 seconds.
I do mean that the previous animation is ending too abruptly. Like, The current animation is only half way through its total animation, stops and is interrupted, and the next animation is played.
Harald je napisao/la:Are the events located before the timepoint at which you abort your attack animation and start the next one? Please note that if they occur after you transition to another animation (and the transition is finished since you used AttachmentThreshold = 1f;), they won't be issued.
I am not sure what is meant by Are the events located before the timepoint at which you abort your attack animation and start the next one?

I have a vague understanding of what you may mean, and if I am correct, yes, the timepoint is after the abortion of the current attack animation.

I have tinkered with the values you have described above and it does seem to work after the values have been changed. No matter how fast the attack speed, the events are always being triggered. There is only one issue, the animation itself plays once correctly, and after that seems to break. It is hard to explain what is happening, but it seems that only the first few frames of the animation play and the animation resets.

I set both of the values to:
attackTrack.MixDuration = 3f;
AttachmentThreshold = 3f;
Surzie
  • Postovi: 5

Harald

Surzie je napisao/la:I do mean that the previous animation is ending too abruptly. Like, The current animation is only half way through its total animation, stops and is interrupted, and the next animation is played.
If you want a smoother transition to happen instead of an abrupt stop, you can set trackEntry.MixDuration to your desired number of seconds. Setting it to 0 will set it to 0 seconds and thus makes the transition immediate.
I have a vague understanding of what you may mean, and if I am correct, yes, the timepoint is after the abortion of the current attack animation.
Please note that only events that are passed in the current frame are issued, events that follow after your transition has ended will not be issued. If you want to make sure that certain events are always issued, even when a transition aborts the animation before reaching them, you can register an event handler at e.g. the End or Interrupt event as well (as described here, and a general event overview here).
attackTrack.MixDuration = 3f;
This sets it to three seconds, which is quite long. Are you sure that this is what you intended?
AttachmentThreshold = 3f;
AttachmentThreshold is a value between 0 and 1, setting a higher values does not make sense here. Please see the documentation here.
Avatar
Harald

Harri
  • Postovi: 4104

Surzie

Thank you for the help! It is resolved! I appreciate your time, have a wonderful day!
Surzie
  • Postovi: 5

Harald

Very glad to hear you've figured it out, thanks for getting back to us!
Avatar
Harald

Harri
  • Postovi: 4104


Natrag na Unity