BoxCollider doesn't block when EntityBases overlap



  • Hiya,

    I'm learning V-Play and I would like to create a game pretty similar than BattleCity.

    https://www.youtube.com/watch?v=MPsA5PtfdL0

    Today I'm in the part of creating Blocking Tiles.

    Those blocking tiles should stop the player when it touches them.

    I did a quick example where I just create two entities, with PhysicsWorld, and simulate the fall of one box, where the ground was able to stop its movement.

    This works perfectly:

    BoxCollider {
    
    anchors.fill: parent
    
    bodyType: Body.Static // the body shouldn't move
    
    }
    

    I thought that Body.Static is the only thing that you need to set to make an object "solid".

    When I pass this logic to my current project, The player keeps overlapping the tile. That's so annoying...

    I did some investigation, but I couldn't find a way to solve it, the documentation of BoxCollider doesn't seem obvious and I don't think that PhysicsWorld is necessary to this endeavor.

    Here is the code for your reference:

    //Main.qml

    import VPlay 2.0
    import QtQuick 2.0
    GameWindow{
        id:gameWindow
        Rectangle{
            id: background
            anchors.fill: parent
        }
    
        onSplashScreenFinished:{
            mov.running=true
            world.running=true
        }
        EntityManager{
            id:mng
            entityContainer: scene
        }
        Scene{
            id: scene
    
            Missile {
                id: wrapBullet
            }
    
            PlayerTank {
            }
    
            EntityBase{
                entityType: "wall"
                width: 20; height:20
                x:parent.width/2; y:parent.height/2
                Rectangle{
                    id:rectangleWall
                    anchors.fill: parent
                    color: "yellow"
                }
    
                BoxCollider{
                    id: wallCollider
                    categories: Box.Category2
                    collidesWith: Box.Category1
                    anchors.fill: parent
                    bodyType: Body.Static
                }
            }
        }
    }
    

    //Firing Square

    import VPlay 2.0
    import QtQuick 2.0
    EntityBase{
        Rectangle{
            id:rect
            width: 32; height:32;
            color: "blue"
            focus: true
            
            property string direction: "None"
            property EntityManager manager: EntityManager{}
    
            Keys.onPressed: {
                if(event.key  === Qt.Key_Up){
                    console.log("Going Up")
                    y=y-5
                    rect.direction="Up"
                }
                else if(event.key === Qt.Key_Down){
                    console.log("Going Down")
                    y=y+5
                    rect.direction="Down"
                }
                else if(event.key === Qt.Key_Left)
                {
                    console.log("Going Left")
                    x=x-5
                    rect.direction="Left"
                }
                else if(event.key === Qt.Key_Right){
                    console.log("Going Right")
                    x=x+5
                    rect.direction="Right"
                }
                else if(event.key === Qt.Key_Space){
                    console.log("Firing")
                    var pointFiring= mapToItem()
    
                    //Create Entity
                    var bulletPoint=mapToItem(parent,rect.x,rect.y)
                    //Fire entity
                }
            }
        }
    }
    

    // I don't attach Missile because it's not relevant for this issue.

    So the question... How to make a object "solid" following the BoxCollider logic?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.