Rick Posted February 5, 2010 Share Posted February 5, 2010 I'm having an issue where my lua script for my camera works fine from the editor, but when I load the map that has this script in it from my own C++ program it acts differently. I will now describe acting differently. The script is my ThirdpersonCamera script. Basically wherever you place the editor model is where the fw.camera will be placed. Then you assign it a target and it'll point at that target. This all works just fine and great when run from the editor. function object:Update() local t = object.model:GetTarget(0) if GetGlobalString("mode") == "GAME_MODE" then if object.oneTime == false then object.cameraPivot:SetPosition(EntityPosition(object.model, 1), 1) object.playerCube:Hide() local p = t:GetPosition(1) p.x = p.x + object.targetOffset.x p.y = p.y + object.targetOffset.y p.z = p.z + object.targetOffset.z object.playerPivot:SetPosition(Vec3(p.x, p.y, p.z)) object.cameraPivot:Point(object.playerPivot, 3, 1, 0) fw.main.camera:SetMatrix(object.cameraPivot.mat) object.oneTime = true end if t == nil then else -- the pivot to follow the player around -- debug code --object.cameraCube:SetPosition(object.cameraPivot:GetPosition()) --object.playerCube:SetPosition(object.playerPivot:GetPosition(1)) end else if t ~= nil then local p = t:GetPosition(1) p.x = p.x + object.targetOffset.x p.y = p.y + object.targetOffset.y p.z = p.z + object.targetOffset.z object.playerPivot:SetPosition(Vec3(p.x, p.y, p.z)) object.cameraPivot:SetPosition(EntityPosition(object.model)) end -- debug code --object.cameraCube:SetPosition(object.cameraPivot:GetPosition()) object.playerCube:SetPosition(object.playerPivot:GetPosition()) end end I then created my own C++ program that has all the lua stuff loaded and working. I know this because I load the scene and I can see from the engine.log that it's loading the lua files and I see the lua stuff working. The problem is that the camera when ran from my program isn't in the same place. It looks to be at the target location instead of the editor model location. I did set the global string "mode" to "GAME_MODE". So in the script object.cameraPivot:SetPosition(EntityPosition(object.model, 1), 1) should set the camera pivot to the location of the object model. Then fw.main.camera:SetMatrix(object.cameraPivot.mat) should set the fw.camera (which I did create in my C++ program and expose to lua) to the object.cameraPivot. So what am I missing? Quote Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 So after the camera gets set I added this code: pos = fw.main.camera:GetPosition(1) Notify("fw.main.camera pos = "..pos.x..","..pos.y..","..pos.z) I do get different values when ran from my C++ program vs running from the editor. They are running the same script and loading the same scene so why would I get different values? C++ program gives (in x,y,z) -9.96,22.05,-18.01 Editor gives -13.9,26.4,-11.3 Quote Link to comment Share on other sites More sharing options...
Canardia Posted February 5, 2010 Share Posted February 5, 2010 Of course you get different camera positions, since in C++ the camera starts from 0,0,0 when you create it, and in Editor it starts from where you left it in Editor. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 But I am setting camera position based on a thingoids position. So it shouldn't matter where the camera starts. Once this script runs it should set the position of the camera to the thingoid position. Quote Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 What I don't get is if I do object.cameraPivot:SetPosition(object.model:GetPosition(1), 1) pos = object.cameraPivot:GetPosition(1) Notify("object.cameraPivot position = "..pos.x..","..pos.y..","..pos.z) I get (-13, 26, -11) Then a couple lines down if I do fw.main.camera:SetPosition(object.cameraPivot:GetPosition(1), 1) pos = fw.main.camera:GetPosition(1) Notify("camera = "..pos.x..","..pos.y..","..pos.z) I get (-23,48,-29) What am I missing? If the position of object.cameraPivot is A and I set fw.main.camera to object.cameraPivot position, how can fw.main.camera position be B? Quote Link to comment Share on other sites More sharing options...
Canardia Posted February 5, 2010 Share Posted February 5, 2010 If your pivot is not at offset 0,0,0 from the model, then you would these kind of results. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 Would that matter between running from the editor vs running from my own C++ program? I mean both are running this lua script and in there I just do: object.cameraPivot = CreatePivot() to create the pivot. This all works perfect in the editor. There just must be something I'm missing between running from the editor to running from C++. Quote Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 Here is the C++ code to expose the fw BP L = GetLuaState(); lua_pushobject(L, framework); lua_setglobal(L, "fw"); lua_pop(L, 1); Do I need to do something else with this? I wouldn't think so because I can set the fw.main.camera to the position I know it should be and it works, but for some reason when I try to set the position based on the pivots position it doesn't work. I get the offset thing, but I can't understand how the lua scripts would create the pivot differently based on when ran from my C++ code vs the editor. It's all being done in the script. Quote Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 Could it be something around: object.cameraPivot = CreatePivot() object.playerPivot = CreatePivot() object.cameraPivot:SetParent(object.playerPivot, 1) I do set the parent with the cameraPivot. But again, same script being ran so I wouldn't think so. Quote Link to comment Share on other sites More sharing options...
VicToMeyeZR Posted February 5, 2010 Share Posted February 5, 2010 what this means is there is obviously a difference in scripting entities, and using them in C++... So Lua scripts in the editor are NOT the same as in the c++ program Quote AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD Link to comment Share on other sites More sharing options...
Rick Posted February 5, 2010 Author Share Posted February 5, 2010 The The fact that I do the following object.cameraPivot:SetParent(object.playerPivot, 1) is causing the issue. If I comment that out, then the camera is placed in the correct location. However, I want that behaviour. I want the cameraPivot to move when the playerPivot moves. 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.