Jump to content

Recommended Posts

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.

post-286034-0-22652400-1394705667_thumb.

 

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 )endendend

and 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!

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 )
or

local item_inst = SpawnPrefab( item_name )inst:AddChild(item_inst)

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 by Mr. Tiddles

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 by squeek

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...