Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Character Animation while moving object

Author
Message
Essal
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location: inside your webcam, watching YOU.
Posted: 9th Oct 2009 21:32 Edited at: 9th Oct 2009 21:38
Hey guys,
I am having a problem, and its killing me here -
I have a animated character (a free rigged character i downloaded, and animated myself) and all I want it to do is make it play the walking animation whenever it is walking forwards (W) or backwards (S)- but the closest i have gotten to achieving that result, is making the animation start looping when i press W or S, and then keep playing even if i release the buttons.

So I thought to myself; Why not make a variable, called IsMoving?
and i wrote this code;

But now, the animation does not play at all.

Also,
I am using Sparky's collision, could that have anything to say in the matter?
My object moving code looks like this;



Any help would be greatly appreciated!

Thanks in advance.

Essal.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 9th Oct 2009 23:30
First of all, why do you put semicolons in the middle of "if" statements? For example in this line:



The semicolon after the "if" condition closes the statement, so you create an empty "if" statement that doesn't do anything, and after that comes the dbStopObject which will always be executed because it is not connected with the "if" at all. It's the same issue in every line, and you don't need brackets around single statements and semicolons after brackets either.

In the third line, you also mis-typed the "IsMoving" check, because you put a single equation mark instead of double. The result is that IsMoving will be set to false and dbStopObject will always be executed, even without the extra semicolon. The compiler should give you a warning for that. To avoid this error, use the ! (not) operator instead of "==false".

But even after these corrections, the code won't work as intended, because if dbLoopObject is continuously called while the key is held down, then it will always start playing the animation from the beginning, so it will only show the first frame. You need to detect the moment when the key is pressed and when it's released. For example, try something like this:



Not tested but it should work. Hopefully. Anyway, the idea is to detect when the status of the object changes from moving to stationary and back, and call the looping and stopping functions only at those moments.

(Maybe I would also store the result of the dbKeyState checks in variables, instead of repeated function calls.)
Essal
18
Years of Service
User Offline
Joined: 15th Jan 2006
Location: inside your webcam, watching YOU.
Posted: 9th Oct 2009 23:50 Edited at: 9th Oct 2009 23:55
Thanks for the advice
Worked like a charm!
Appreciate it.. I'm still kinda new to Dark GDK.

Login to post a reply

Server time is: 2024-10-01 14:35:29
Your offset time is: 2024-10-01 14:35:29