Jump to content

Finding entity in scene.


AggrorJorn
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Aggror
Link to comment
Share on other sites

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.

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

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