- Edited
[Unity] Frame freeze
I have a problem, i really need some help here. I loaded the spineboy example scene where you can walk around with spineboy using his spineboycontroller.cs... It works perfectly, and i started the project, made my character and everything, imported it to unity, and started making a script using help from this forum... I made the character jump and walk around, but here's the problem, when i hold a "D" key, he walks right normally how he's sopposed to, and when i release it, it needs to stop and make the idle animation play instead of walking one, but he's not doing that, he is just freezing the last frame of the walking animation except playing the idle one... The jumping works complitly normal though. Then i tryed using the spineboy controller's code on my character instead, but it does the same thing.... What is the problem, i think my code is not even important here becouse it's not a problem in it, becouse it acts the same as the spineboys and does the same thing. Sorry for spelling mistakes, i'm typing fast i'm nervos:
if (Input.GetKeyUp (KeyCode.Space))
{
if(CanJump == true)
{
skeletonAnimation.state.SetAnimation (0, "Jump", false);
skeletonAnimation.state.AddAnimation (0, "Idle", true, 0);
rigidbody2D.AddForce (Vector2.up * JumpH);
}
}
if (Input.GetKeyDown (KeyCode.D))
{
if (skeletonAnimation.AnimationName == "Idle")
{
skeletonAnimation.state.SetAnimation (0, "Walking", true);
}
}
if (Input.GetKeyUp (KeyCode.D))
{
if (skeletonAnimation.AnimationName == "Walking")
{
skeletonAnimation.state.SetAnimation (0, "Idle", true);
}
}
if (Input.GetKey (KeyCode.D))
{
if (skeletonAnimation.AnimationName == "Walking")
{
transform.Translate (Vector2.right * WalkingSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2(0,0);
}
}
if (Input.GetKeyDown (KeyCode.A))
{
if (skeletonAnimation.AnimationName == "Idle")
{
skeletonAnimation.state.SetAnimation (0, "Walking", true);
}
}
if (Input.GetKeyUp (KeyCode.A))
{
if (skeletonAnimation.AnimationName == "Walking")
{
skeletonAnimation.state.SetAnimation (0, "Idle", true);
}
}
if (Input.GetKey (KeyCode.A))
{
if (skeletonAnimation.AnimationName == "Walking")
{
transform.Translate (Vector2.right * WalkingSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2(0,180);
}
}
Well even when i play the animation in my character data, there's a player there, i play one animation, and then i press another one, and they mess up becouse they play over eachothers... I have to press setup pose every time.... I think it was a total mistake to use this program, it's great fo animating and everything, but seriously if i need to wait for 5 days for an answer, it's not worth it in my opinion, i don't have time to waste.
I'm sorry for the wait, but most of the time there are plenty of people here to answer questions. Nate who is the programmer on Spine is away this week and I'm not a programmer myself.
Have tried doing
if (Input.GetKeyUp (KeyCode.D))
{
skeletonAnimation.state.SetAnimation (0, "Idle", true);
}
Instead of
if (Input.GetKeyUp (KeyCode.D))
{
if (skeletonAnimation.AnimationName == "Walking")
{
skeletonAnimation.state.SetAnimation (0, "Idle", true);
}
}
Maybe if(skeletonAnimation.AnimationName == "Walking")
is false. I recommend checking with just simple console prints to see if your if statement is actually firing.
Well even when i play the animation in my character data, there's a player there, i play one animation, and then i press another one, and they mess up becouse they play over eachothers... I have to press setup pose every time
Make sure they are playing on the same trackIndex, if one animation plays on trackIndex 0 and another on trackIndex 1 they will play on top of each other.
Shiu wroteI'm sorry for the wait, but most of the time there are plenty of people here to answer questions. Nate who is the programmer on Spine is away this week and I'm not a programmer myself.
Have tried doing
if (Input.GetKeyUp (KeyCode.D)) {
skeletonAnimation.state.SetAnimation (0, "Idle", true);
}Instead of
if (Input.GetKeyUp (KeyCode.D)) { if (skeletonAnimation.AnimationName == "Walking") { skeletonAnimation.state.SetAnimation (0, "Idle", true); } }
Maybe
if(skeletonAnimation.AnimationName == "Walking")
is false. I recommend checking with just simple console prints to see if your if statement is actually firing.Well even when i play the animation in my character data, there's a player there, i play one animation, and then i press another one, and they mess up becouse they play over eachothers... I have to press setup pose every time
Make sure they are playing on the same trackIndex, if one animation plays on trackIndex 0 and another on trackIndex 1 they will play on top of each other.
Shiu, thank you for answering. Finally someone. Well, i tryed doing it without the if(skeletonAnimation.AnimationName == "Walking")
in the first place, i added it later... the track index is always 0 here, so yeah... This is wierd, why do i have theese problems ?
Oh, and if you want, i can record it so you see what's happening...
The kind of better way to implement this is to have your character's logical state machine be pollable (even internally) and then have a delegate/event or processing method called whenever the state changes. The change in state can signal when you should do something with the animation.
This is a solid game character logic regardless.
To cater to the complex animations needed by 3D games, what Unity's native system (Mechanim) does is have an intervening animation state machine that checks character logic variables and events (button presses, character speed and turning, current state, user-defined booleans and enums) and then decides and processes what animations to play and mix together and transition between. It kind of does what I described above, but in a much more complicated and specific way.
Mechanim itself isn't available to us to interface with Spine because of its closed nature, but a Spine-Unity Mechanim Animation State Machine functionality is in the works. No ETA.
The other option (currently what you're working towards) is that your character logic will keep telling the animation system to play an animation, and the animation system keeps checking if it's already playing or if it should start over or not. This is a bit wasteful and doesn't scale well. This is especially true if you have to keep dereferencing members, passing through properties and comparing strings like that: skeletonAnimation.AnimationName == "Walking"
.
Pharan wroteThe kind of better way to implement this is to have your character's logical state machine be pollable (even internally) and then have a delegate/event or processing method called whenever the state changes. The change in state can signal when you should do something with the animation.
This is a solid game character logic regardless.
Didn't really get you there ^^^^
But about the text under it, yeah, i tought it's becouse of that too, but didn't get an idea of how to make it work, i'm gonna try something now.
Oh God i'm totally lost around here...
And guys, it's not becouse of the skeletonAnimation.AnimationName == "Walking" thing, the code was acting like this before too, i added this later to it so when it wants to walk, it can only walk if the idle animation is currently on the track, and it can stop only if it's playing the walking one....
Of course it's not because of that line. That's not logically incorrect. It's just slow and won't scale well, for performance or for your ability to understand and manage your own code if your character did many more things than just running.
Here's what I meant:
1) Store your character's state in variables. Use booleans, use floats, use enums whatever you need.
2) Every Update
, check if those values changed meaningfully. Use conditions that detect changes that are meaningful to the animation.
3) If a change is detected, tell your skeletonAnimation to do something.
Pharan wroteOf course it's not because of that line. That's not logically incorrect. It's just slow and won't scale well, for performance or for your ability to understand and manage your own code if your character did many more things than just running.
Here's what I meant:
1) Store your character's state in variables. Use booleans, use floats, use enums whatever you need.
2) EveryUpdate
, check if those values changed meaningfully. Use conditions that detect changes that are meaningful to the animation.
3) If a change is detected, tell your skeletonAnimation to do something.
I don't think that i will be able to, but i will give it a try, thank you for opening my eyes on this one anyways... Oh, and if you're not too busy or anything, could you try and do a code for this ? Becouse i'm so lost with this one, like never before.
I tryed things, didn't menage to make it work :/ I don't know anymore, maybe it's the best for me to get an easier program that will fit good with unity ?