Rick Posted January 10, 2010 Share Posted January 10, 2010 Why does the below code produce a larger physics box than cube mesh? object.cube = CreateCube() object.cube:SetScale(Vec3(2,2,2)) -- default size object.body = CreateBodyBox(2,2,2) Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 10, 2010 Share Posted January 10, 2010 It should be the same size. EDIT: And I verified that it is, by adding those 3 lines to the windmill script (replace object with entity). The only explanation to your phenomena I can imagine is that you see only half of the mesh, since the lower half is under the terrain, since you created the mesh at 0/0/0. 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 January 10, 2010 Author Share Posted January 10, 2010 No, the cube is in the middle of the body box for me so that's not it. This is what it looks like for me. http://dl.dropbox.com/u/1293842/img.jpg Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2010 Author Share Posted January 10, 2010 Can you try it in your editor. Drop this folder anywhere in your leadwerks folder. http://dl.dropbox.com/u/1293842/Pi-Cube.zip Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 10, 2010 Share Posted January 10, 2010 It seems to me that :SetScale is doing ScaleEntity, which is usually the wrong thing to do. Lua seems to be missing ScaleMesh, which would do it right. As a workaround you can just do: object.body = CreateBodyBox(1,1,1) 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 January 10, 2010 Author Share Posted January 10, 2010 The size will need to be variable though. You'll be able to size it to whatever you want from properties. I thought you said it worked for you with those 3 lines of code, but now you seem to be saying it's not? Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 10, 2010 Share Posted January 10, 2010 Yes, it works when you add those 3 lines to windmill, without all the other stuff you have, ESPECIALLY without parenting. 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 January 10, 2010 Author Share Posted January 10, 2010 lol, well the parenting is kind of key I see now that if I comment out the parenting it's the right size, but I have to have the parenting, so like you said ScaleMesh would probably do it. Although looking at the wiki, it uses ScaleEntity() and parenting just like I'm doing: http://www.leadwerks.com/wiki/index.php?title=CreateBodyBox Quote Link to comment Share on other sites More sharing options...
macklebee Posted January 10, 2010 Share Posted January 10, 2010 object.body:SetParent(object.cube,1) 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 January 10, 2010 Author Share Posted January 10, 2010 Thank macklebee, that did it! I wonder why the wiki tutorial doesn't do that and it works there? Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2010 Author Share Posted January 10, 2010 The issue I have now, is when I set the bodymass to 1, the body falls, but the cube doesn't go with it. Any ideas? require("scripts/class") require("Scripts/hooks") require("Scripts/linkedlist") local class=CreateClass(...) function class:InitDialog(grid) self.super:InitDialog(grid) group = grid:AddGroup("Cube") group:AddProperty("size", PROPERTY_VEC3, "0", "Cube Scale") group:AddProperty("mat", PROPERTY_FILE, "", "Material") group:AddProperty("body_mass", PROPERTY_FLOAT, "", "Body Mass") group:AddProperty("entity_type", PROPERTY_INTEGER, "", "Entity Type") group:Expand(1) end function class:CreateObject(model) local object=self.super:CreateObject(model) function object:CreateCube(size, mass, type) -- delete if already exists if object.cube ~= nil then object.cube:Free() object.cube = nil object.body:Free() object.body = nil end -- create object.body = CreateBodyBox(size.x, size.y, size.z) object.body:SetMass(mass) EntityType(object.body, type) object.cube = CreateCube() object.cube:SetScale(size) object.body:SetParent(object.cube, 1) -- paint object.mat = LoadMaterial(object.matFile) object.cube:Paint(object.mat) -- position local scale = object.cube:GetScale() local pos = object.model:GetPosition() pos.y = pos.y - (scale.y / 2) object.cube:SetPosition(pos) object.cube:SetRotation(object.model:GetRotation()) end -- defaults object.model = model object.matFile = "abstract::cobblestones.mat" object.bodyMass = 1 object.entityType = 1 object.size = Vec3(2, 2, 2) object.cube = nil object.body = nil object.material = nil -- create default cube object:CreateCube(object.size, object.bodyMass, object.entityType) function object:SetKey(key,value) if key == "mat" then object.matFile = "abstract::"..value object.mat = LoadMaterial(object.matFile) object.cube:Paint(object.mat) elseif key == "size" then object.size = StringToVec3(value) object:CreateCube(object.size, object.bodyMass, object.entityType) elseif key == "body_mass" then object.bodyMass = tonumber(value) object:CreateCube(object.size, object.bodyMass, object.entityType) elseif key == "entity_type" then object.entityType = tonumber(value) object:CreateCube(object.size, object.bodyMass, object.entityType) 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:Update() if GetGlobalString("mode") == "GAME_MODE" then else -- editor mode -- moves the editor model to the top of the cube local scale = object.cube:GetScale() local pos = object.model:GetPosition() pos.y = pos.y - (scale.y / 2) --object.cube:SetPosition(pos) --object.body:SetPosition(pos) --object.cube:SetRotation(object.model:GetRotation()) end end function object:Free(model) if object.cube ~= nil then object.cube:Free() object.cube = nil end if object.body ~= nil then object.body:Free() object.body = nil end --if object.mat ~= nil then -- object.mat:Free() --end self.super:Free() end end Quote Link to comment Share on other sites More sharing options...
Niosop Posted January 10, 2010 Share Posted January 10, 2010 Parent it the other way and just set the body scale and not the model scale. 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 January 10, 2010 Author Share Posted January 10, 2010 Parenting the other way works, except the box and the cube aren't together (the physics body moves with my editor object but the box is created at the origin, however when I move the physics body the box does move also), but from my understanding you can't scale bodies after they are created. You can, but the physics gets messed up from what I remember. That shouldn't be an issue though as I just recreate the physics body when the size changes anyway. Just need to get the cube at the same position as the body now. [EDIT] I got it. Thank you! Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2010 Author Share Posted January 10, 2010 Here's something interesting. So I uncomment the code in the update method that positions the body so I can move the body around in the editor. When I run the game everything drops and works as expected except for 1 detail. The longer I'm in editor mode and then switch to game mode, the faster the objects drop to the ground. For example, if I sit in editor mode for 1 second, then switch to game mode, the objects fall at a decent speed. Then if I go back to editor mode and wait 10 seconds and then go back into game mode, the objects fly to the ground really fast. It's almost because I SetPosition() of the body in editor mode that it's really building up speed behind the scenes, and when I don't call SetPosition() anymore, it still has the speed at which it would be falling. How can I get around this? Ideally I would think that once SetPosition() is called it resets any velocity the body would have so when it's not called on the body anymore the velocity is starting from scratch. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2010 Author Share Posted January 10, 2010 Has anyone experienced issues when setting the position of a physics body and then not setting the position and letting physics happen on the body, but the body velocity is really fast now. Almost like while set position was being called on it, it was increases it's velocity even though it was standing still? Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 10, 2010 Share Posted January 10, 2010 This fast movement happens when you don't call fw.Update() in each frame. It then tries to catch up the lost time when you next time call fw.Update(). 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 January 10, 2010 Author Share Posted January 10, 2010 I can't think of a reason why fw.Update() isn't being called. Nothing is blocking it from being called. Quote Link to comment Share on other sites More sharing options...
Canardia Posted January 10, 2010 Share Posted January 10, 2010 If you do SetPosition on a physics body in each frame, then it might also do the same, as a missing fw.Update(). You should use AddBodyForce with CalcBodyVelocity to simulate SetPosition on physics bodies. 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 January 10, 2010 Author Share Posted January 10, 2010 hmm, well this is all just for editor mode so you can position the cube where you want it to be when the game runs. I need the cube to follow the position of the editor object model. Would you think there would be a way to reset the physics body so it doesn't have this high velocity after SetPosition() is stopped being called on the body? That way I could do that on the first run inside the update method. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 10, 2010 Author Share Posted January 10, 2010 I found a work around. I set the mass to 0 when in editor mode, and the first time in Update in game mode is where I set the mass to whatever the user sets in the properties. That seems to work out well. 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.