Rick Posted February 14, 2010 Share Posted February 14, 2010 So after the main game loop in lua I try to unparent the camera with fw.main.camera:SetParent(0, 1) But I get an error: Value at index (2) is not an object. I thought passing 0 as the first parameter was how you removed a parent? I also tried 0 as the second parameter but the same error. Any ideas what I'm missing? Quote Link to comment Share on other sites More sharing options...
Rick Posted February 14, 2010 Author Share Posted February 14, 2010 Anyone have any ideas on how I can unparent an object? Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 14, 2010 Share Posted February 14, 2010 i assume just like with everything in lua when you want to remove it, you would need to set the parent to nil Quote 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 More sharing options...
Rick Posted February 15, 2010 Author Share Posted February 15, 2010 fw.main.camera:SetParent(nil, 1) didn't work Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 15, 2010 Share Posted February 15, 2010 havent tried it for the camera but it works when models are parented to each other and you press a button to unparent them with nil... without seeing the whole code, can only guess what the problem would be... Quote 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 More sharing options...
Rick Posted February 15, 2010 Author Share Posted February 15, 2010 This is the Thingoid. Basically what it does is allow rotating around target 0. I place an object in the middle of my map and place this Thingoid in the map also. Make the link on index 0, position this Thingoid where I want the camera to be and run it. It then allows me to rotate the camera around the object. When I escape game mode, I then can't move the camera at all in editor mode. require("scripts/class") require("scripts/hooks") --- create the class local class=CreateClass(...) function class:InitDialog(grid) self.super:InitDialog(grid) end function class:CreateObject(model) local object=self.super:CreateObject(model) object.model = model object.oneTime = false object.leftMouseDown = false object.mouseX = 0 object.mouseY = 0 object.camRotationX = 0 object.camRotationY = 0 Notify("Unparent camera") fw.main.camera:SetParent(nil, 1) -- unparent the camera. when we leave game mode this gets called and should free the camera from being parented function object:Free(model) self.super:Free() end function object:SetKey(key,value) if key == "" then else return self.super:SetKey(key,value) end return 1 end function object:GetKey(key,value) if key=="" then else return self.super:GetKey(key,value) end return value end function object:Initialize() end function object:ReceiveMessage(message,extra) if message == "" then else self.super:ReceiveMessage(message,extra) end end function object:Update() if GetGlobalString("mode") == "GAME_MODE" then if object.oneTime == false then -- position the camera to the editor object fw.main.camera:SetPosition(object.model:GetPosition(1), 1) -- make the target the parent to the camera fw.main.camera:SetParent(object.model:GetTarget(0), 1) object.oneTime = true end if MouseHit(1) == 1 then object.mouseX = MouseX() object.mouseY = MouseY() MoveMouse(200, 200) -- 200 doesn't mean anything. It's just picked at random. It doesn't matter what it is since we are always finding the difference from where the mouse started HideMouse() end if MouseDown(1) == 1 then local mx local my mx = MouseX() - 200 my = MouseY() - 200 MoveMouse(200, 200) object.camRotationY = object.camRotationY + mx / 4.0 -- this is left and right --object.camRotationX = object.camRotationX - my / 4.0 -- this is up and down object.leftMouseDown = true object.model:GetTarget(0):SetRotation(Vec3(0, -object.camRotationY, 0), 1) elseif MouseDown(1) ~= 1 and object.leftMouseDown == true then MoveMouse(object.mouseX, object.mouseY) ShowMouse() object.leftMouseDown = false end --fw.main.camera:SetPosition(object.model:GetPosition(1), 1) object.model:SetPosition(fw.main.camera:GetPosition()) fw.main.camera:Point(object.model:GetTarget(0), 3, 1, 0) end end end Quote Link to comment Share on other sites More sharing options...
Niosop Posted February 15, 2010 Share Posted February 15, 2010 Save the original parent in a variable and set it back before it exits? Maybe it's parented to scene or something. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted February 15, 2010 Author Share Posted February 15, 2010 This results in the notify telling me the camera parent is nil local p = fw.main.camera.parent if p == nil then Notify("camera parent is nil") end It's very strange. After I exit game mode when I right click the mouse acts like normal. It is hidden and when I unpress the right mouse it moves to the center of the screen just like normal camera in edit mode. I can't move with the keys and the camera doesn't rotate though. Quote Link to comment Share on other sites More sharing options...
Rick Posted February 15, 2010 Author Share Posted February 15, 2010 I think I'll just hack around it with a pivot and just parent that to the object and set the cameras matrix to the pivots when in game mode. 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.