Jump to content

ForEachEntityInAABBDo with prefabs loaded by scripts


thehankinator
 Share

Recommended Posts

I have a script that places traps. I don't want to the player to be able to lay the traps on top of each other so I call ForEachEntityInAABBDo in the space the trap would take, if there isn't anything there I place the trap. The problem I am running into is if I place a trap to the left then another to the right I cannot place one in the center because both the left and right trap are returned by ForEachEntityInAABBDo. If I do a IntersectsAABB check in the ForEachEntityInAABBDo callback I can confirm that the AABBs do NOT intersect. I've verified that the parent for the entities is nil. I've tried calling UpdateAABB (with all the options). Is it possible that there is something special about loading a prefab from a script when it comes to hierarchy and ForEachEntityInAABBDo?

 

Check code:

world:ForEachEntityInAABBDo(self.entity:GetAABB(Entity.GlobalAABB), "ArrowWeapCheckPosition", self.entity)

 

Callback:

function ArrowWeapCheckPosition(entity, extra)
if entity:GetCollisionType() == Collision.Trigger then
 if entity:GetAABB(Entity.GlobalAABB):IntersectsAABB(extra:GetAABB(Entity.GlobalAABB)) then
  System:Print("Yep")
 else
  System:Print("Nope")
 end
 extra.script.valid_position = false
 return
end
end

 

Spawn code:

local trap = Prefab:Load("Prefabs/Traps/arrow_trap.pfb")
trap:SetParent(nil, true)
trap:SetPosition(pickinfo.position, true)
trap:AlignToVector(pickinfo.normal)
trap:UpdateAABB(Entity.LocalAABB + Entity.GlobalAABB + Entity.RecursiveAABB)
trap:Show()

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...