AggrorJorn Posted May 11, 2010 Share Posted May 11, 2010 I have been going to trough some Lua stuff that is a little bit harder for me to understand. Lets say I want to position my camera at an object placed in the scene. When I press the space key, I need to retrieve the position of the object and place the camera there. Should I be using something like this? if KeyHit(KEY_SPACE)==1 then gameMode = 1 class = classnametable[ "MyObject" ] if class~=nil then for model,object in pairs(class.instances) do fw.main.camera:SetPosition(model:GetPosition(1)) end end end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 14, 2010 Author Share Posted May 14, 2010 Anyone? Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 14, 2010 Share Posted May 14, 2010 I would get the entity by its name, this works: scene = LoadScene("abstract::tunnels.sbx") while AppTerminate()==0 do if KeyHit(KEY_ESCAPE)==1 then break end if KeyHit(KEY_SPACE)==1 then m_entity = scene:FindChild("node_1") if m_entity ~= nil then camera:SetPosition(m_entity:GetPosition(1)) end end UpdateAppTime() world:Update(AppSpeed()) SetBuffer(gbuffer) world:Render() SetBuffer(BackBuffer()) world:RenderLights(gbuffer) DrawText(UPS(),0,0) Flip(0) end Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Rick Posted May 14, 2010 Share Posted May 14, 2010 I think this depends on where you are doing this. If you are doing this in the main lua file like ZioRed did that should work. If you are doing it in an object script then I seem to remember I was using a different able than the classnametable. Check if there is an objecttable. I think I used that before. In the download section you can look for my Pi-Main and in there I loop through the table to call functions in all the object scripts that I created. for k,v in pairs(objecttable) do if v.Initialize ~= nil then v:Initialize() end end Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted May 15, 2010 Author Share Posted May 15, 2010 (edited) I''l have a look on both suggestions. thanks. * Okay Ziored's way works good. But when I have a very large scene with lots of objects, isn't this very computer power comsuming? I mean the scene can hold thousand of objects, is looking through every child in the scene very heavy? haven't looked in your pi script yet Rick, but I will do that to. Edited May 15, 2010 by Aggror Quote Link to comment Share on other sites More sharing options...
ZioRed Posted May 15, 2010 Share Posted May 15, 2010 But when I have a very large scene with lots of objects, isn't this very computer power comsuming? I mean the scene can hold thousand of objects, is looking through every child in the scene very heavy? I don't know how the engine stores the object list, but if it uses a correspondent of C# Hashtable to store the list then recovering an item from it through its key (in that case the object's name would be the key of the item) is the quicker way. However I think that if you should cycle through every object to find the one you need then every other way should have almost the same CPU consuming. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com 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.