simpleprogrammer Posted October 22, 2010 Share Posted October 22, 2010 Hello All, I am a noobie to Lua and c++, I would like to learn this in Lua. However i would like to control mesh animation loaded into a Leadwerks scene. Currently i have a mesh animated and want to control the animation with a keyboard key with sound started at the same time. So how do you control a animated mesh with a keyboard key when it's loaded into a scene? Also my question is, Do i need to control the animation from inside the Editor and save it with the scene. Let me know if am not clear on anything. Thank you, Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted October 22, 2010 Share Posted October 22, 2010 Hi, You can play the animation either with Lua or C++. Lua has the advantage that it can do the animation realtime in the editor. Which one do you want to use? Quote Link to comment Share on other sites More sharing options...
simpleprogrammer Posted October 22, 2010 Author Share Posted October 22, 2010 Thank you for your responce, Would it be to much to ask for an example in both? Hi, You can play the animation either with Lua or C++. Lua has the advantage that it can do the animation realtime in the editor. Which one do you want to use? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted October 22, 2010 Share Posted October 22, 2010 I don't know how to do it entirely in C++ but this is a way for Lua. When you do it with Lua you can either use the main program or use a per entity script (object script). I am going to explain the last one. Lets say you have a gmf named soldier.gmf. You need to make soldier.lua file in the same folder as the gmf file. Then add some code: require("scripts/class") local class=CreateClass(...) function class:CreateObject(model) local object=self.super:CreateObject(model) function object:Render() if KeyDown(KEY_UP)==1 then frame = (AppTime()/35.0) % (ENDFRAME-STARTFRAME) + 1 model:Animate( frame, 1,0, 1 ) end end replace ENDFRAME with the last frame of the animation and STARTFRAME with the first frame of the animation. The /35 is used for the speed of the animation. You have to tweak it a little to your own needs. Quote Link to comment Share on other sites More sharing options...
simpleprogrammer Posted October 22, 2010 Author Share Posted October 22, 2010 Thank you that totaly helps I am on my way now. I don't know how to do it entirely in C++ but this is a way for Lua. When you do it with Lua you can either use the main program or use a per entity script (object script). I am going to explain the last one. Lets say you have a gmf named soldier.gmf. You need to make soldier.lua file in the same folder as the gmf file. Then add some code: require("scripts/class") local class=CreateClass(...) function class:CreateObject(model) local object=self.super:CreateObject(model) function object:Render() if KeyDown(KEY_UP)==1 then frame = (AppTime()/35.0) % (ENDFRAME-STARTFRAME) + 1 model:Animate( frame, 1,0, 1 ) end end replace ENDFRAME with the last frame of the animation and STARTFRAME with the first frame of the animation. The /35 is used for the speed of the animation. You have to tweak it a little to your own needs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.