Jump to content

LUA: How to animate models


Scott Richmond
 Share

Recommended Posts

I have animation working for both looped and one-shot animations in my Weaponwerks Library.

 

For looping:

frame = (AppTime()/100.0) % (endframe-startframe) + startframe

 

For one shot animations:

animstarttime = AppTime() -- Call this once when you first start the animation

...

frame = ((AppTime()-animstarttime)/100.0) % (endframe-startframe) + startframe

 

 

Then simply call model:Animate(frame,blend,0,1)

 

In cases where you need to speed-up or slowdown the application, you multiply the value to the left of the % (modulus) sign by a speed factor. 1.0 plays at default (has no effect), 0.5 halves the speed, 2.0 doubles the speed, etc.

 

If you need to compare the current frame (which is a floating point number) to a given frame (which is an integer) (i.e. I do this to check for sounds I have set to play at certain animation frames), round it to a whole frame using either math.ceil or math.floor (or code up a function like I did to ceil if the decimal place is .5 or higher and floor is less than .5)

  • Upvote 1

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Ah fantastic work TylerH! Thanks mate, I'll give it a crack tonight. :D

 

(May as well start using this rep system. +1 rep for you :P )

 

Thanks :D

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

  • 3 weeks later...

I would do your animation in the object:Render() function. That way animation only has to be performed on models that actually get drawn.

 

Hrm, are you able to point to an example of that function in use Josh?

Programmer, Modeller

Intel Core i7 930 @ 3.5GHz | GeForce 480 GTX | 6GB DDR3 RAM | Windows 7 Premium x64

Visual Studio 2008 | Photoshop CS3 | Maya 2009

Website: http://srichnet.info

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...