Hello everyone, I have the following problem. I create a ColCube and attach it to a container. Then I put another container on top of it. This one has 2 doors attached. Now the ColCube of the first container should locate the upper one with getElemntsWithin and say that there is a container above and the lower one is not selected. But only the upper one is free.
self is the container ingame object
function Container:constructor(zRotation, defaultDimension)
self.activated = false
self.defaultDimension = defaultDimension
self.colshape = nil
self.containerStartPosition = self:getPosition()
self.zRotation = tonumber(zRotation)
self.rightBorder = Object(3062, 0, 0, 0)
self.leftBorder = Object(3062, 0, 0, 0)
self.rightBorder:setAlpha(255)
self.leftBorder:setAlpha(255)
self.alreadyRotated = false
self.checkColliderWidth = 3
self.checkColliderSize = 7.05
self.rightBorder:attach(self, 0, 3.4, -0.1)
self.leftBorder:attach(self, -0.1, -3.5, -0.1)
engineSetModelLODDistance(3062, 400)
end
function Container:setCorrectCheckCollider() -- Zum erstellen des CubeShape
local attachFactor = self:getAttachFactor()
self.colliderCheckCube = createColRectangle(0, 0, self.checkColliderWidth, self.checkColliderSize)
if not (self:isRotatedToXAxis()) then
local containerCheckColliderSize = self.colliderCheckCube:getSize()
self.colliderCheckCube:setSize(containerCheckColliderSize.y, containerCheckColliderSize.x)
end
self.colliderCheckCube:attach(self, -1.5 + self:getOffsetCenterXAxis(self.checkColliderWidth), 3.5 + (self.checkColliderSize * attachFactor), 1.5)
end
function Container:isFree()
if(self.colliderCheckCube) then
local elements = self.colliderCheckCube:getElementsWithin("object")
outputChatBox("#elements: "..#elements)
if(#elements > 0) then
for _, object in ipairs(elements) do
outputChatBox("elements: "..object:getModel())
if not (object == self or object == self.leftBorder or object == self.rightBorder or object:getModel() == 3798) then
self.colliderCheckCube:destroy()
return false
end
end
return true
else
return true
end
else
return false
end
end
Strangely, the isFree function often returns an object that is not in the container. Most of the time, however, the colshape does not recognize any objects in itself, although there clearly are some.
Have someone an idea?