when I fire with the mouse click the animation does play of my character firing, However the fireball is fired before the animation. how do I fix this situation?
Try using animation events so you instantiate the Fireball at a specific moment, just remember the following: Animations Events do not support methods with more than one parameter, do not support bools as parameters.
Hi Bdragon,
Did you share this video because it solved your problem?
See also:
- Forum User Guides : How to mark a topic as solved
no I still nee to try this out. I’m more of a visual learner. so this might help out others if it works.
I’m getting close to getting this done but I’m having issues. Now he is firing 2 fireballs. one is right away and the other is right after the animation. \i do not know what to do now I tried like 4 things and not really helping.
Could you please share more information on what you did and have in Unity?
sure, like what?
``
void OnFire(InputValue value)
{
//Test();
//Debug.Log(value);
//if(!isAlive)
//{
//return;
//}
playerAnimator.SetTrigger("isCastingFire");
//Instantiate(fireBall, castFireBall.position, transform.rotation);
FireBallAttack();
}
public void FireBallAttack()
{
if(!isAlive)
{
return;
}
Instantiate(fireBall, castFireBall.position, transform.rotation);
}
Try to move the event to the second last keyframe and test your game again to see if the player still fires 2 fireballs.
Add a Debug.Log to the method to see how often it gets called. Also make sure that there are not multiple animators on the player.
And how long is your animation? What do the numbers mean? Frames? Seconds?
Is “Loop” enabled in the Shooting animation? Does the animation state have got an exit condition defined? Also make sure that Transition Duration is set to 0.
Thank you so much Nina,
Solution,
you can’t call a already defined function on an event in the Animations tab after an animation (Like “OnFire()”). so I created a Trigger called “isCastingFire” and that is set between “Any State” and my “Player Casting” animation. next I created another method called “FireBallAttack()” this function was originally calling from the “OnFire()” method because I thought I needed to call it after the keypress was entered, I would call that function as shown above. but now I know that the trigger I set (isCastingFire) is what will make the fireBall cast after the animation. so in reality I was casting the fireball twice. once when I called the FireBallAttack() method from the "onFire"method. and onece after the animation that was what i wanted from the trigger I set isCastingFire. so in putting an event call to after the animation is done was the key and just calling the method from that after teh animation is done.
``
void OnFire(InputValue value)
{
playerAnimator.SetTrigger(“isCastingFire”);
}
public void FireBallAttack()
{
if(!isAlive)
{
return;
}
Instantiate(fireBall, castFireBall.position, transform.rotation);
}
Good job on solving this problem.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.