- Home /
Simple Attack Script Problem
Hi everybody, I'm trying to learn about unity3d so, I'm making a simple game just to learning.
I'm having a hard time to scripting a attack script. Unity doesn't have a attacking asset, 'cuz it may vary in a game (shoots, swords, kung fu)
Anyway, I've made a script that play the atack animation if I push left ctrl. See below.
function Update () {
if(Input.GetKeyDown("left ctrl")){
animation.Play("attack");
}}
The problem is: It doesn't play the full animation (the animation has 60 frames), so, how can I solve this?
Sorry for de dull question, I really wanna learn the unity scripting, but my way of learning, is praticing.
PS: Sorry for my English, I'm Brazilian.
Can you tell us how much of your animation is playing? Have you checked that your animation hasn't been cut off for some reason (either in the program you used to make it or in Unity)?
Oi !
A good trick, in the inspector set the animation to play automatically. in that way it will at least play ONE TI$$anonymous$$E when you start the Play button.
So, you can see if your animation is good.
sorry, my mistake.... It wasn't 60 frames, it's just 20, by the way, it's playing just 10, when he draws the sword. I've used maya (i'm beginner in that too), but in maya, the animation goes well. If the animation has been cut in unity, I don't know why. Is there a default play time for an animation? If there is, how can I extend?
Note: If I press repeatly the key, the animation runs in a funny way.
yes, click on animation (apple 6) and you can change the time fairly easily. hope it helps!
First, try Get$$anonymous$$eyUp it will happen when you release the key rather than pressing it down. Sometimes that will help. If that doesn't solve anything, you may need to pause for a certain amount of time to make sure it finishes the animation. http://www.burgzergarcade.com/tutorial/hack-slash-rpg-unity3d-game-engine-tutorial/265-unity3d-tutorial-melee-attack-animation-par
This tutorial might help.
Answer by RjToni · Aug 30, 2012 at 10:42 PM
Guys, I DID IT! I've just put the attack animation in another layer, now the animation is going well. I'm still having a problem with the CrossFade, but I'll try another way.
You know, like attack walking or jumping. Maybe I should make a different animation for them, though.
The script is like this:
function Start () {
animation["attack"].layer = 1; }
function Update () {
if(Input.GetKeyUp("left ctrl")){ animation.Play("attack");
}}
Thanks to kristercollin, Gilead7 and Fattie, for your patience and kindness ^__^
Answer by RjToni · Aug 30, 2012 at 08:14 PM
So, In the inspector, is already in play automatically. I've checked bake animation too ( i'm using IK), and I realize, it's playing just ONE frame, not 10. Even if keep pressed the key down, just play one frame and stops. All the other animations is playing ok (idle, run and jumping)
problem could relate to I$$anonymous$$ ?? suggest post new question here, problem with I$$anonymous$$ import $$anonymous$$aya ..?
I'll do that. It's really bugging me, but when I find the solution, I'll post here
Your answer
Follow this Question
Related Questions
Unity3D AI using animations 1 Answer
my animation script does not work 0 Answers
What am I doing wrong with this attack script? 2 Answers
animating character 1 Answer
Switch between idle animations 0 Answers