Forums

OverviewFelgo 2 Support (Qt 5) › BoxCollider doesn't block when EntityBases overlap

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18664

    Charlie Hdz

    Hiya,

    I’m learning Felgo and I would like to create a game pretty similar than BattleCity.

    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 Felgo 3.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 Felgo 3.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.

    Many thanks!

     

     

    #18672

    Marcin

    Hi Charlie

    Yes, you are right.
    Body.Static option makes it not affected by gravity or forces.

    I don’t know for sure but have few things you can check.

    Please check:
    1. I suggest to have only one EntityManager(the best with id entityManager). Create it at some high level, for now can be even in your Main.qml or the main game scene, if it’s a separate file.
    All entities etc should have access to this entity manager by using it’s id no problem.
    Don’t create more than one EntityManger if you’re not sure 100% it is really needed.
    2. I see you are using categories and collidesWith properties for colliders. Be 100% sure that both entities, which need to collide with each other, are configured properly and have the right settings to collide with the other.
    3. Last bit is to be sure that your entities are always created in the scope of the PhysicsWorld.
    That means are either created directly inside of that PhysicsWorld parent or it’s children,  or that the entityContainer of EntityManger is set at that physics world parent or any of its children.

    I would start with these first.
    I am pretty sure you know but, to check, remember all entities which in any way need to be affected by physics world, need to have colliders defined.

    Hope it helps.

    #18674

    Marcin

    One last thing I would suggest is t be sure that not only entities overlap but also their physical colliders.
    If you enable Physical world.debugDrawVisible, and set it to true, do you also see colliders overlapping?
    Maybe colliders are not properly positioned within the entities.

    #18683

    Günther
    Felgo Team

    Thanks Marcin, I can agree with all your points! 😉

     

     

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support