#I'm new to Unity, is it possible to cancel the reload animation by sprinting?
1 messages · Page 1 of 1 (latest)
Hey, sorry for the late reply, yeah, you can definately do that. Just call the _animator.CrossFade("Idle", 0.15f)
Thank you for the help! Is that something that I'm going to do in the animator? Or is it something I'm placing inside of the FPSController script? I'm hoping I'm at least on the right track here. 😅
Yeah, you just need to access the Animator component and call the CrossFade method. So you can do it in the FPSController, right
Damn, I've got no idea how to do what you're saying haha, I ran at it for a few hours but I'm not sure if I'm just supposed to put this under onReload, or what but I'll keep trying to plug up at it, but I'd love some elementary school instructions on this one LOL
Alright, no problem, here is an example code snippet you could use:
private void OnSprintStarted()
{
//...
_animator.CrossFade("Empty", 0.15f);
}
That's an example for the FPSController script, just find the OnSprintStarted method there and insert that crossfade line
Damn, that didn't seem to work; was there anything else I needed to do after that?
I also tried "Idle" as well, but no dice. This one is really messing me up lol
You just need to add this line _animator.CrossFade("Empty", 0.1f); at the end of the OnSprint function
Oh yeah, I had ended up doing that, but sadly no dice. Reload anim plays without interruption
This works perfectly on my end
Could you share the full code?
Really? Let me try again on an unedited controller, maybe it's something on my end, if not I'll share the full code!
also, is character or weapon animation still playing?
Yeah for me the weapon's reload animation was still playing, basically eating that input on sprint
Okay, then everything is functioning correctly on your end. To stop the weapon animation, you need to get a reference to the weapon animator. It is a non-public field, that resides in the weapon component, so you need to expose it like this: public Animator WeaponAnimator => weaponAnimator; - add this line in the FPSWeapon script
Then, get back to the OnSprint method in the FPSPlayer, and add this line: GetActiveWeapon().WeaponAnimator.Play("Idle");
The only script that (I think) you're talking about that I could find was the Weapon script inside of each weapon from the demo; but I error when putting
public Animator WeaponAnimator => weaponAnimator; since weaponAnimator doesn't exist;
I'm sure I'm in the wrong script; and since I am, GetActiveWeapon() errors as well since the FPSController doesn't have access to the animator I'm guessing, because that's also erroring.
I see that the Weapon script DOES have an animator named _weaponAnimator that's private; but setting it to public hasn't helped me much either so I'm not going to play with it too much haha
So you are working with the FPS Animation Framework, not the Pack, right? The FPSController is from the Framework, and the solution above is for the Pack FPS Player script