Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

collision on voxel world could be very easy.
First it’s a must to calculate the participant place and dimension divide by the block dimension
Instance: participant.place.x + participant.dimension / block.dimension
Then in the event you’re utilizing any form of grid then examine that place/grid if it has a stable block kind in it.

Right here is the pattern code from my voxel recreation:

void Digicam::collision(float dx, float dy, float dz)
{
    /* AABB collision checker */
    
    float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, y5;
    x1 = flooring((m_position.x - m_width) / m_block.getBlockSize());
    y1 = flooring((m_position.y - m_bottom) / m_block.getBlockSize());
    z1 = flooring((m_position.z - m_width) / m_block.getBlockSize());
    x2 = flooring((m_position.x + m_width) / m_block.getBlockSize());
    y2 = flooring((m_position.y + (m_top+2)) / m_block.getBlockSize());
    z2 = flooring((m_position.z + m_depth) / m_block.getBlockSize());
    
    // caught? go up
    if(flooring(m_position.y / m_block.getBlockSize()) < m_worldSize.y) {
        whereas(Sorts::getSolidBlocks( m_map.getInPosition(flooring(m_position.x / m_block.getBlockSize()), flooring(m_position.y / m_block.getBlockSize()), flooring(m_position.z / m_block.getBlockSize())) )) {
            m_position.y += m_block.getBlockSize();
            y1 = flooring((m_position.y - m_bottom) / m_block.getBlockSize());
            y2 = flooring((m_position.y + (m_top+2)) / m_block.getBlockSize());
            if(flooring(m_position.y / m_block.getBlockSize()) > m_worldSize.y) break;
        }
    }
    
    // vertical collision
    
    if(Sorts::getSolidBlocks(m_map.getInPosition(x1, y1, z1)) || Sorts::getSolidBlocks(m_map.getInPosition(x2, y1, z1)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x2, y1, z2)) || Sorts::getSolidBlocks(m_map.getInPosition(x1, y1, z2))) {
        
        if(dy < 0) {
            m_position.y = y1 * m_block.getBlockSize() + m_block.getBlockSize() + m_bottom;
            m_direction.y = 0;
            m_onGround = true;
        }
        m_collision[1] = true;
    }
    
    if(Sorts::getSolidBlocks(m_map.getInPosition(x1, y2, z1)) || Sorts::getSolidBlocks(m_map.getInPosition(x2, y2, z1)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x2, y2, z2)) || Sorts::getSolidBlocks(m_map.getInPosition(x1, y2, z2))) {
        
        if(dy > 0) {
            m_position.y = y2 * m_block.getBlockSize() - (m_top+2) - .01;
            m_direction.y = 0;
        }
        m_collision[1] = true;
    }
    
    // horizontal collision
    
    x3 = flooring((m_position.x - dx - m_width) / m_block.getBlockSize());
    y3 = flooring((m_position.y - dy - m_bottom) / m_block.getBlockSize());
    z3 = flooring((m_position.z - dz - m_width) / m_block.getBlockSize());
    x4 = flooring((m_position.x - dx + m_width) / m_block.getBlockSize());
    y4 = flooring((m_position.y - dy + (m_top+2)) / m_block.getBlockSize());
    z4 = flooring((m_position.z - dz + m_depth) / m_block.getBlockSize());
    y5 = spherical(y3+(y4-y3)/2); // earlier y place
    
    if(Sorts::getSolidBlocks(m_map.getInPosition(x1, y3, z3)) || Sorts::getSolidBlocks(m_map.getInPosition(x1, y3, z4)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x1, y4, z4)) || Sorts::getSolidBlocks(m_map.getInPosition(x1, y4, z3)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x1, y5, z3)) || Sorts::getSolidBlocks(m_map.getInPosition(x1, y5, z4))) {
        
        if(dx < 0) {
            m_position.x = (x3-1) * m_block.getBlockSize() + m_block.getBlockSize() + m_width;
            m_direction.x = 0;
        }
        m_collision[0] = true;
    }
    
    if(Sorts::getSolidBlocks(m_map.getInPosition(x2, y3, z3)) || Sorts::getSolidBlocks(m_map.getInPosition(x2, y3, z4)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x2, y4, z4)) || Sorts::getSolidBlocks(m_map.getInPosition(x2, y4, z3)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x2, y5, z3)) || Sorts::getSolidBlocks(m_map.getInPosition(x2, y5, z4))) {
        
        if(dx > 0) {
            m_position.x = (x4+1) * m_block.getBlockSize() - m_width - .01;
            m_direction.x = 0;
        }
        m_collision[0] = true;
    }
    
    if(Sorts::getSolidBlocks(m_map.getInPosition(x3, y3, z1)) || Sorts::getSolidBlocks(m_map.getInPosition(x4, y3, z1)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x4, y4, z1)) || Sorts::getSolidBlocks(m_map.getInPosition(x3, y4, z1)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x3, y5, z1)) || Sorts::getSolidBlocks(m_map.getInPosition(x4, y5, z1))) {
        
        if(dz < 0) {
            m_position.z = (z3-1) * m_block.getBlockSize() + m_block.getBlockSize() + m_depth;
            m_direction.z = 0;
        }
        m_collision[2] = true;
    }
    
    if(Sorts::getSolidBlocks(m_map.getInPosition(x3, y3, z2)) || Sorts::getSolidBlocks(m_map.getInPosition(x4, y3, z2)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x4, y4, z2)) || Sorts::getSolidBlocks(m_map.getInPosition(x3, y4, z2)) ||
        Sorts::getSolidBlocks(m_map.getInPosition(x3, y5, z2)) || Sorts::getSolidBlocks(m_map.getInPosition(x4, y5, z2))) {
        
        if(dz > 0) {
            m_position.z = (z4+1) * m_block.getBlockSize() - m_depth - .01;
            m_direction.z = 0;
        }
        m_collision[2] = true;
    }
    
}

Btw. The m_map is a grid that checks the block kind on this planet
and dx, dy, dz are the route of the participant

and this is find out how to use the collider:

// participant motion
m_position.x += m_direction.x * dt;
collision(m_direction.x, 0, 0); // collision detector
m_position.y += m_direction.y * dt;
collision(0, m_direction.y, 0); // collision detector
m_position.z += m_direction.z * dt;
collision(0, 0, m_direction.z); // collision detector

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *