Hubert005 Posted May 17, 2022 Share Posted May 17, 2022 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? Link to comment
Spakye Posted May 18, 2022 Share Posted May 18, 2022 Hello, unless im missing something i think the issue is the syntax, you wrotte 20 hours ago, Hubert005 said: getElementsWithin("object") instead of getElementsWithinColShape( colshape, "object" ) Link to comment
Hubert005 Posted May 20, 2022 Author Share Posted May 20, 2022 Hey @Spakye, unfortunately this makes no difference also with getElementsWithinColShape( colshape, "object" ) I have the same result. Link to comment
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