- Home /
Handling Movement - Animations
Hello everyone. Ill cut to the chase.
So, I was wondering what was the best practice when using GUI. I want to move a player using a button.
But when Im testing it on my device I get small glitches...So I came to you guys and tell me what would be the ideal way of doing this?
Should the function be called from within the button? or Keep it as Im doing(update function)?
Also when Im calling for Animations, where should be better? When Moving? or When Pressing the button?(inside the move function or once the button is pressed.
Thank you for your time and help!
////EDIT Here's the scripts:
GUI:
void OnGUI(){
_downButton = DownButtonClicked();
}
private bool DownButtonClicked(){
return GUI.RepeatButton(DownArrowRect,"", "Dpad_ArrowD");
}
update(){
CheckDownButtonClicked();
}
void CheckDownButtonClicked(){
if (_downButton){
_animManager.SetDirection(2);
_animManager.SetMoving(true);
_playerController.MoveDown ();
}
Now, here's the tricky part. The PlayerObject has 3 attached gameObjects with their individual animations.(simulating clothes). The idea is that:
A)The animations of the 4 gameObjects(player + clothes) don't unsync when clicking multiple times the repeat button.(which they do on my mobile device...)
Heres _animManager:
public void SetMoving(bool isMoving){
//This one sets the body animation.
_anim.SetBool("isMoving",isMoving);
//This one sets the shirt animation.
if(_shirtController != null)
_shirtController.SetMoving(isMoving);
///You get the picture.
if(_legsController != null)
_legsController.SetMoving(isMoving);
if(_hairController != null)
_hairController.SetMoving(isMoving);
}
So my question is, am I doing this the proper way?
Thanks again.
Really hard to tell. Are you using $$anonymous$$ecanim or Legacy? What are the glitches?
CPU's nowadays run thousands of millions of instructions per second so unless you're building for an old device you should be able to call the animation from wherever you want.
If you think the animation isn't running when it should and it might be code related post the code and I'll see if I can spot where the problem is although I only really do C# so you'd need someone else to help if it's complex JS.
@$$anonymous$$mmpies
I've updated the question with the script of the GUI. Its C# so we're good.
Thank you for your time!
That's O$$anonymous$$, not that familiar with OnGUI as I was working on DFGUI and now the new 4.6 UI but I guess that parts working for you so I can ignore.
Still not 100% sure I know what you're trying to do. This appears to sending the information constantly whenever the button is down. I'm not sure you need to.
Hard to say with what I can see but if calling an animation that normally takes a second or so to play out.
Let's get some more information. I'm guessing _anim$$anonymous$$anager and _playerController are either mecanim animation Controller or references to your own script.
I'm working in 3D with mecanim so I tend to think everyone else is as well, which isn't always the case.
So some questions: 2D/3D? Animations = Legacy/$$anonymous$$ecanim/Sprites? What are _anim$$anonymous$$anager and _playerController? SetDirection I'm assu$$anonymous$$g a float and Set$$anonymous$$oving clearly a bool but what about $$anonymous$$oveDown() does movement only happen if that's constantly being called.
Sorry for all the questions, oh and you could just move the if(_downButton) as it's checked every time but essentially it looks like it should work.
Do you have any screen capture software like CamStudio so you can post a video of what's goin wrong?
@$$anonymous$$mmpies
Ok, so the game is 2D. , Animations: Sprites, _anim$$anonymous$$anager is the manager of the animations of each gameObject(body,shirt,legs). If I call it, Im looking to start animating the object. _PlayerController takes care of the movement of the gameObject, so, if the object is moving, we need to animate the player. $$anonymous$$oveDown is a function inside the controller, this controller moves the player towards the y Axis(just as if you were playing pokemon/zelda). Heres a video of what happens. You can't really tell, but when I click on the movement buttons quickly, the animation unsyncs.... https://www.dropbox.com/s/aoj9dqt8rq19en0/latestTestVid.mov?dl=0
@$$anonymous$$mmpies
Towards what the glitches were, I managed to eli$$anonymous$$ate a few, but my main question here is why are the animations of the gameObjects unsynced if I click quickly the button...and How could I bypass/eli$$anonymous$$ate/solve this?
//?EDIT
I've checked the animations and all are at the same sample rate, have the same timelapse between each frame and have the same transitions.
Answer by Mmmpies · Dec 12, 2014 at 09:06 PM
OK I see what it is, unfortunately I'm working in 3D animations not 2D but that said animation is animation.
How does the 2D sprite animation system handle things does it set frame 1 then frame 2 and so on?
I think you could maybe, and this is just speculation as I haven't done any work in 2D sprite animation, do this.
Leave your _shirtController _legsController etc. to handle what your character currently looks like, then have a _playerMovementController script the runs the animations for all items in the character. That way all the animations are called together.
Or if you can reference individual frames in the 2D sprite setup then make sure all animations are on the same frame.
EDIT:
Sorry for the extra work for no benefit, and sorry for the delay (was night time where I am).
OK I don't know how the 2D animation system works but is this a workable solution...
You call the animation to show the sprite of the feet/legs of the body even though the trousers and shoes completely cover the legs and feet. Is it a workable solution to simply stop the lower animation if the higher animation covers it?
Or a better way would be to make the animation so it only has to call one frame for that body part. For one thing it would save a whole heap of animations from being called. For example if the body part == legs and wearing trousers then only display the trousers not bare legs as well. If wearing shorts combine the sprite for each frame of animation with the legs so you just get one image.
Depends on how you have the game setup. If you have to keep the current method how are your layers setup, is the body set to be further back?
@$$anonymous$$mmpies
So, I changed the _anim$$anonymous$$anager function and moved it to the movement function. But still, If I click quickly my GUI the animation will be unsynchronized... The sprite animation system sets frame 1 then 2 and so on but what I did was dragging the sprites to the animation screen. Then add the transitions on the animator screen...
@$$anonymous$$mmpies
Sorry for the delay as well, this sounds like a solution but my artists are not going to like this hahaha. (Cropping the body part.) But what I don't understand is why would the body be the only part out of sync? I clicked the sprite component to see how well the armor and the legs match on the animation and they do match even if I fastclick the GUI.... I've doubleChecked the animations and have the same sampleRate and time lapse between frames... :/
@$$anonymous$$mmpies is it possible to force an animation from X frame?
I work in 3D not 2D so I'm not sure.
Ask it as as a separate question.
If you don't get an answer I'll try creating a 2D project to see if I can get a solution.
Your answer
Follow this Question
Related Questions
Animation - Forcing To Start at X Frame 1 Answer
Best way to - Animation Sync - Multiple gameObjects. 0 Answers
Enter Trigger, play animation(s) and sound FX 1 Answer
How to reset an animation from Animation to beginning before turning the gameobejct off? 0 Answers
Animating GUI Texture - Help 4 Answers