Jump to content

Help with animate command


simpleprogrammer
 Share

Recommended Posts

Hello All,

I am tyring to use the findchild command to animate a model in a scene file.

Does anyone know what i am doing wrong with my lua script. I get the model to just move a little bit then stop.

 

Help what am i doing wrong?

Thank you,

Leroy

 

 

require("Scripts/constants/engine_const")
//Register the Path
RegisterAbstractPath("")


//Setup the display mode
Graphics(800,600)



//Frame Work of the leadwerks


fw = CreateFramework()

//Setup the camera
camera = fw.main.camera
camera:SetPosition(Vec3(0,2,-10))


camRotation=Vec3(0,0,0)
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
HideMouse(1)



//Home made scene
scene = LoadScene("abstract::leroy1.sbx")

//Find Inworld Camera
cameraleroy = scene:FindChild("start")

AppLog(cameraleroy)
//Position Camera in start point
fw.main.camera:SetPosition(cameraleroy:GetPosition())


framebegin = 0
frameend = 0
frame =0

//Find animated engine inworld
leroyengine = scene:FindChild("engineone")





while KeyHit(KEY_ESCAPE)==0 do


//Animate engine model
framebegin=100.0
frameend=227.0
frame=AppTime()/100.0
frame=frameend-framebegin+framebegin
Animate(leroyengine,frame,1.0,0,true)



UpdateAppTime()



//Camera Look Around

gx=Curve(MouseX()- GraphicsWidth()/2,gx,10)
gy=Curve(MouseY()- GraphicsHeight()/2,gy,10)
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)

camRotation.x = camRotation.x+gy /10
camRotation.y = camRotation.y-gx /10
camera:SetRotation(camRotation,1)

//Run engine inworld





//keys
move = Curve(KeyDown(KEY_W)-KeyDown(KEY_S),move,10)
strafe = Curve(KeyDown(KEY_D)-KeyDown(KEY_A),strafe,10)
camera:Move(Vec3(strafe /15,0,move,15))

fw:Update()
fw:Render()

Flip(0)


end








Link to comment
Share on other sites

er-- why not use the object script i showed you the other day for your model?

 

but in any case, look at this line:

frame=frameend-framebegin+framebegin

essentially you are just setting the frame variable to frameend each time... you need to cycle the frame value like this:

frame = (frame Mod (frameend - framebegin)) + framebegin

granted this just one way to do it... there are plenty of ways to calculate the frame parameter for the Animate command...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

er-- why not use the object script i showed you the other day for your model?

 

but in any case, look at this line:

frame=frameend-framebegin+framebegin

essentially you are just setting the frame variable to frameend each time... you need to cycle the frame value like this:

frame = (frame Mod (frameend - framebegin)) + framebegin

granted this just one way to do it... there are plenty of ways to calculate the frame parameter for the Animate command...

 

I like the way you did it and really appreciated your help. But i made this code work in C++ and couldn't sleep

at night with out learning how to make it work the same in lua. Does that make sence.

 

 

I tried the (frame Mod (frameend - framebegin)) and i get a Lua error string "start.lua 56 expected near 'Mod' when i try and run it.

Why does this happen? if remove the mod the script will run but just move the engine one frame.

 

Thank you,

Leroy

Link to comment
Share on other sites

you would have to use the equivalent lua command for modulo, which would be:

frame = math.fmod(frame, frameend - framebegin) + framebegin

or

frame = frame % (frameend - framebegin) + framebegin

 

and you would not need the object script if you use this... but that is the whole purpose of the object script. Also, you could have easily just used the equivalent code from the object script inside this standalone script.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

you would have to use the equivalent lua command for modulo, which would be:

frame = math.fmod(frame, frameend - framebegin) + framebegin

or

frame = frame % (frameend - framebegin) + framebegin

 

and you would not need the object script if you use this... but that is the whole purpose of the object script. Also, you could have easily just used the equivalent code from the object script inside this standalone script.

 

Thank very much for your help. IT"S WORKING NOW AGAIN>>>>>>>

 

So i could use the sample code in the stand alone script and use the findchild command to call it out from the scene file.

I need more practic finding the equivalent command. I didn't know where to start being a noobie and all.\

 

;)

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