Jump to content

Recommended Posts

Posted

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?

Posted

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

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

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

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

Posted

Save the original parent in a variable and set it back before it exits? Maybe it's parented to scene or something.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Posted

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.

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.

×
×
  • Create New...