Animation with clicking Mouse

I have to ask you guys after some attempts. My small game is about 3rd person view. In game, I use mouse to relocation my character and do running animation (Sinbad model). Attached is a brief description for the problem I have with all approaches I know so far.

I have CharacterState and CharacterControl. In CharacterState, I use ActionListener to get new location of character from 1 mouse click then pass this parameter to CharacterControl to create nomalized vector from current and new location, the controlUpdate will keep translate my character into new locations base on normalized vector until it reach the last one. Everything is working fine.

The point is I want to do run animation during the moving. This should be easy if I keep pressing a button and do channel.setAni(“run”). But I just want to use 1 click and both moving and running with animation automatically. As what I have tried is I put the animation in update loop like translation but its freeze because the program repeat the animation fast and no animation is completed. Then I have tried to put animation on actionListenner, however I use only 1 click, the animation works unstoppable. I have to click again to stop it or change to another animation.

Hope you guys can help me.

You need to know when to stop it of course, like distance to clicktarget is less than 10cm.
And then stop it.

Yeah, but the thing is I have no trigger to stop it. I can check the updated current location but dont know where I should but the stop. If I put it in actionListenner, it needs a click mouse as input trigger. if I put the stop in update, it doesnot work as I tried because the update gonna repeat the animation really fast and results the freezze.

I really get the feeling, that you might want to learn java better first, as this looks like a problem that comes from missing practice.
No offense intended with this, but probably every week spend with basic Java stuff before doing a game in a 3d engine will save you several weeks of painful problems later on.

Thanks, but I am definitely sure that my problem is not about the basic Java. It’s just about I do not know what JmonkeyEngine could support me to do with this case. I am following the JME beginner tutorial book, this book is enough to write the a basic game following the library the engine support. I think you may no understand the issue I have. The thing is what should I need to stop the character? Of course I need to check if the current location is close enough to the destination location. Its definitely need a loop to check this condition. What should I do to stop running animation? where in the code I should change the animation like idle animation. In the loop? no way, because running animation can not be in the loop (freeze effect). Or somewhere in input trigger like anctionListener or analogListener, yeah , but in case I use only one click, I have to leave it automatically instead of click again.

The this I am missing is a method that library to use animation automatically.
I hope you can give some advice to solve this problem instead of tell me come back from beginning to learn Java. If I was born again, I will learn Java from 3 years old.

I glanced at the question while getting ready for my day of fun with java.

Why not just setup the “Marco Polo” situation?

for the life of me I cannot remember where I picked this concept up at beyond that it has that term because there is a child’s game where one child says “Marco” and the other child has to say “Polo” while running around.

So, the Mouse click specifies a place to go to for your character in the game world. The character behavior triggers to play the correct animation and movement towards the desired point is started at some arbitrary velocity. The thing is… here is where the whole thing starts and some time will pass before the desired location is reached.

Next up, the character arrives at a location that is “close enough” to the desired spot (in a 3D world this is always the case in a floating point operation type setup, so make sure this trigger is specified to cover a “range” that would not be skipped during a time interval between “frames”). This condition triggers the whole “Stop moving, switch to idle animation”.

So, just formulate your game logic around that concept and it should work just fine for you.

Oh, to the forum, as a bonus question: for this situation… Would this situation be best covered as an AppState for “Marco” and a Control for “Polo”? the Appstate would cover both, to be sure. But from my current understanding of Control, would it be possible to pick a Control class to contain the logic of stopping velocity and switching to idle if a certain condition is met? Just checking…

Sure all the walk logic can be done with a controll, that could even detach itself when finsihed.

1 Like