Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. BoxCollider doesn't block when EntityBases overlap
Qt 6.12 LTS is out! See what's new in the release blog

BoxCollider doesn't block when EntityBases overlap

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 650 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Charlie_Hdz
    wrote on last edited by
    #1

    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?

    Kind Regards,
    Enrique Hernandez
    gearstech.com.mx
    chernandez@gearstech.com.mx

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved