Jump to content

Colshape getElementsWithinColshape doesn't work


Recommended Posts

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...