Jump to content

Collision and Playerprox problems.


NikMik

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!

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...