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.

Newcomers DBPro Corner / My player will not animate when walking.

Author
Message
cyangamer
16
Years of Service
User Offline
Joined: 2nd Jun 2008
Location: Houston, TX, USA
Posted: 2nd Jan 2009 04:09
Hi, I'm having a problem with my character movement function. I'm using states to decide what section of frames should be played, but DBPro won't play them. Loop Object just won't work!

Here's my function:


Player State always shows 1, but no animation. What could I be missing here?

Currently working on - Enemy AI and Action Battle System

the sig limit needs to be raised...
Guyra
19
Years of Service
User Offline
Joined: 10th Nov 2005
Location: Norway
Posted: 2nd Jan 2009 04:27 Edited at: 2nd Jan 2009 04:36
Try changing this:


To this:


If you constantly set the model to start looping, it will never get past the first frame of animation.


cyangamer
16
Years of Service
User Offline
Joined: 2nd Jun 2008
Location: Houston, TX, USA
Posted: 2nd Jan 2009 21:25
Thanks. That didn't solve the problem, but it did reveal something. This
does not work because model is constantly playing the frame 173 while player_state is 0. So while it technically is animating, it's just animating the idle phase, which is just 1 frame. (I didn't initially consider that an animation, but now that it has come to my attention, this may lead to bigger problems if not rectified now).

How do I make it switch between phases as I should?

Currently working on - Enemy AI and Action Battle System

the sig limit needs to be raised...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 2nd Jan 2009 22:01
First - animation frames are floats so you can mess with frame positions like 1.2 thru 1.8 for example.

second - your code could be made more efficient. you have stuff like:



and this sort of structure might be better


Have a blast - Looks good otherwise

--Jason

cyangamer
16
Years of Service
User Offline
Joined: 2nd Jun 2008
Location: Houston, TX, USA
Posted: 3rd Jan 2009 03:05
Thanks, Jason, but I need to at least get my program to work. Then I can worry about optimization and structure. I'll refer to that later though.

No luck on my end as far as getting it to animate. I've switched loop object with play object, but it still doesn't work.

Here's what I have:


HELP would be greatly appreciated!

Currently working on - Enemy AI and Action Battle System

the sig limit needs to be raised...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jan 2009 03:24
You know the frames... SO.... Come up with an arbitrary amount of FRAME PLAY per millisecond and stuff it in a float.. say named: AnimSpeedMult# for Animation Speed Multiplier. Start with super small numbers so you see it work.. from there you can figure out what looks right. like 0.01 or even smaller...

Set up a basic timer elapsed dilly:


OldTime = NewTime; NewTime=dbTimer(); // DarkGDK
OldTime# = NewTime#: NewTime# = TIMER() ` DBC/DBP


Next Have a variable you populate to get elapsed time. This is the amount of time each loop takes.


ElapsedTime = NewTime - OldTime; //DarkGDK
ElapsedTime# = NewTime# - OldTime# ` DBC/DBP


Next, you need a variable to always be the FRAME the model is in... remember its a float:


AnimFrame#


Ok... Now we don't need PlayObject or Loop Object anymore -- AND you have more control!!!!!!!!!!!!!!!!!!!

So here is the dilly...

1: In your main loop you find out how much time is elapsed

2: Depending on your player state... You enter the block of code to manage THAT particlar animation - out equiv to play object sorta.

3: In your Player State (let's say Walking block) e.g. if player walking then... (that's where we are) you take the ElapsedTime and multiply it by your arbitrary animation speed: AnimSpeedMult# and store the result in a Temp Variable called TempAnimFrame#

4: Now you check if the new FRAME is With your "Sequence" of frames you have been handing to the play object and loop object commands up untiul now: if TempFrame# > 150 then AnimFrame# = 1 else AnimFrame# = TempFrame#

5: Now Set the object's FRAME to the value of AnimFrame# and your loop is ready for another go around.


Also, the optimization I mentioned is not too complex and will make your code read a little better once you see what's behind my suggestion... it certainly is easier to follow than the while loop you have at the very top of your first post's code snippet - that makes your app literally STOP until the animation is through.

Look - I know what I just explained also seems like unneccessary work but this is timer based movement applied to animation - and gives you complete control - of speed, exact frame starts and stops, and the ability to play forward and backward etc..

Also DO NOT FORGET frames are floats... so the idle thing that is one frame you mention above might be played out like 173 thru 173.9999 or something...


Good Luck...
--Jason

cyangamer
16
Years of Service
User Offline
Joined: 2nd Jun 2008
Location: Houston, TX, USA
Posted: 3rd Jan 2009 04:05 Edited at: 3rd Jan 2009 04:07
Um, I don't think the AnimSpeedMult# is working like it should. Here's what it does:

The ElapsedTime (which goes between 0 and 30) is multiplied with the AnimSpeedMult# (which is 0.1) which gets 3. As a result, the animation only plays the first 3 frames, and at lightning speed. By increasing AnimSpeedMult#, more frames are played, but at that same speed.

Here's my main loop:


And here's the section of PlayerMove that deals with the animation:


It's seems like a pretty nice trick, but I never understood the logic (code-wise) of timer-based movements of any kind. What do I do?

Currently working on - Enemy AI and Action Battle System

the sig limit needs to be raised...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jan 2009 04:23
Look at this project of mine - its all DBPro code...

download it - all three files - open them on top of each other - you'll see why in the web page I'm about to provide (I had too make three zips of same directory - each with different files due to upload limits)

Read the help for key presses... Run it - play it - look for the running soldier dudes on the screen.... Watch how smooth they are ... aside from the abrupt stopping and running again (random # based AI logic... random run - random stand random run etC)

After you've seen it in action - look at the code for in I think IIInfantry.dba See how I did it there.

half the battle is getting the right AnimMult values - because what you're doing is turning the timer to a float, doing some math to get elapsed time in milli seconds (actually having elapsed time in float format is more important the converting timer to a float... the point is you want to multiply float * float to get a float result because usually mixing integer * float gives integer... but whatever...

So now you have a float "elapsed" and you multiply it by this arbitray AnimMult value - if the result is ZERO (say super fast machine and elapsed time is zero - then animation won't work... (note to add check for zero time elapsed and change value to 1 millisec or something so you're not doing ZERO * animmult... but I digress... back to my point - you are multiplying elapsed time by this arbitrary animmult value - and the result is added to your current frame which BTW I might of left that little import detail out...sorry - brain quicker than the fingers... Because what the idea is is to figure out how much to advance the animation based on the amount of time that has elapsed. the animmult value determines the speed your animation will actually "play".

http://code.google.com/p/ironinfantrydbpro/
Follow my sig - select iron infantry - see the progress and galllery - I haven't updated it in awhile but you'll see some screens of development.

--Jason

cyangamer
16
Years of Service
User Offline
Joined: 2nd Jun 2008
Location: Houston, TX, USA
Posted: 3rd Jan 2009 11:41 Edited at: 3rd Jan 2009 12:03
Alas, it works! The speed is adjustable and everything. Thanks for your help!

I also re-worked the movement code to make it more concise. However, the the movement commends must all be in one collective if statement or else some branches never get executed. That's why it was set up the way it was, and why I'm tweaking your example slightly.

Here's what I did:


Currently working on - Enemy AI and Action Battle System

the sig limit needs to be raised...
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jan 2009 14:04

Login to post a reply

Server time is: 2024-11-24 16:37:27
Your offset time is: 2024-11-24 16:37:27