Jump to content

Lua Simple Animation from a sbx


simpleprogrammer
 Share

Recommended Posts

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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...