NikMik Posted March 13, 2014 Share Posted March 13, 2014 This is about the new houses for William 2, which I have almost finished! Just need to sort out these 2 problems, make the roof, and the lamp. COLLISION:The house floor uses this code:inst.decor = {}for k, item_info in pairs( walls ) dofor item_name, item_offsets in pairs( item_info ) dofor l, offset in pairs( item_offsets ) dolocal item_inst = SpawnPrefab( item_name )item_inst.entity:SetParent( inst.entity )item_inst.Transform:SetPosition( offset[1], offset[2], offset[3] )table.insert( inst.decor, item_inst )endendendand other code that tells the walls where to spawn. Unfortunately, by this method I seem to be unable to give the walls physics, so the player and other entities can enter the house through the walls. I tried adding: item_inst.entity:AddPhysics() MakeObstaclePhysics(item_inst, 3)item_inst.Physics:SetCollides(true) but that did nothing. I am new with the whole decor thing. PLAYERPROX:Giving the walls the playerprox component to have the walls go transparent when near works fine at first, but after breaking the house this happens:Stale Component Reference: GUID 104589, @D:/Steam/steamapps/common/dont_starve/data/scripts/entityscript.lua:766...pps/common/dont_starve/data/scripts/entityscript.lua:769: Something is wrong: inst.Transform:GetWorldPosition() stale component reference?LUA ERROR stack traceback: =[C] in function 'assert' D:/Steam/steamapps/common/dont_starve/data/scripts/entityscript.lua(769,1) in function 'GetDistanceSqToInst' D:/Steam/steamapps/common/dont_starve/data/scripts/components/playerprox.lua(7,1) in function 'fn' D:/Steam/steamapps/common/dont_starve/data/scripts/scheduler.lua(170,1) in function 'OnTick' D:/Steam/steamapps/common/dont_starve/data/scripts/scheduler.lua(381,1) in function 'RunScheduler' D:/Steam/steamapps/common/dont_starve/data/scripts/update.lua(87,1)scripts/frontend.lua(712,1) SCRIPT ERROR! Showing error screen I believe this has something to do with the walls being "decor" that was spawned specifically for the house floor and not by their own (see above). Any help would be greatly appreciated! Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/ Share on other sites More sharing options...
squeek Posted March 13, 2014 Share Posted March 13, 2014 The first problem I'm not sure about. It might be more helpful to see the code of wall prefab that you are spawning (why wouldn't the collision code go in there?).The second problem is probably to do with how you're parenting the walls to the house. You should probably use the EntityScript functions rather than calling inst.entity:SetParent directly, as doing that means you are bypassing some potentially important table entries that get set in EntityScript.You should either do:local item_inst = inst:SpawnChild( item_name )orlocal item_inst = SpawnPrefab( item_name )inst:AddChild(item_inst) Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/#findComment-430836 Share on other sites More sharing options...
NikMik Posted March 13, 2014 Author Share Posted March 13, 2014 (edited) The first problem I'm not sure about. It might be more helpful to see the code of wall prefab that you are spawning (why wouldn't the collision code go in there?). inst.entity:AddPhysics() MakeObstaclePhysics(inst, 1)is in the walls' prefabs and work fine when debug spawed on their own. The second problem is probably to do with how you're parenting the walls to the house. You should probably use the EntityScript functions rather than calling inst.entity:SetParent directly, as doing that means you are bypassing some potentially important table entries that get set in EntityScript.You should either do:?local item_inst = inst:SpawnChild( item_name )or?local item_inst = SpawnPrefab( item_name )inst:AddChild(item_inst) Alright, thanks! EDIT: That worked perfectly, thanks! Edited March 13, 2014 by Mr. Tiddles Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/#findComment-430993 Share on other sites More sharing options...
squeek Posted March 13, 2014 Share Posted March 13, 2014 (edited) This is a complete guess, but the physics thing might be related to parenting as well. It's possible that children inherit the physics properties of their parent or something like that. Try spawning a wall using the console, check that its physics work, then set it as a child of something else and see if its physics still work (also try setting the parent to something without physics and then something with physics and see if that affects anything). Edited March 13, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/#findComment-431032 Share on other sites More sharing options...
NikMik Posted March 13, 2014 Author Share Posted March 13, 2014 This is a complete guess, but the physics thing might be related to parenting as well. It's possible that children inherit the physics properties of their parent or something like that. Try spawning a wall using the console, check that its physics work, then set it as a child of something else and see if its physics still work (also try setting the parent to something without physics and then something with physics and see if that affects anything).I thought that would be the case, but that doesn't seem to be the case. I already tested before, and did again just to make sure then. Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/#findComment-431045 Share on other sites More sharing options...
squeek Posted March 13, 2014 Share Posted March 13, 2014 I thought that would be the case, but that doesn't seem to be the case. I already tested before, and did again just to make sure then.So that means if you DebugSpawn a wall, and set its parent, its physics still work? Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/#findComment-431048 Share on other sites More sharing options...
NikMik Posted March 13, 2014 Author Share Posted March 13, 2014 So that means if you DebugSpawn a wall, and set its parent, its physics still work?If it's spawned by a parent, the physics don't work. Only when it's by itself. Link to comment https://forums.kleientertainment.com/forums/topic/32759-collision-and-playerprox-problems/#findComment-431049 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now