Forums

OverviewV-Play 2 Support (Qt 5) › Troubleshooting BoxCollider collisions

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #12606

    Kevin

    Hi,

    I”m following the flappy bird tutorial at:

    http://v-play.net/doc/howto-flappybird-game/?utm_medium=app&utm_source=vplay-samples-app#physics

     

    I seem to be constantly getting the “stopGame” triggered, and i strong reason to suspect it is something to do with the some unexpected collision (i suspect between the pipes and the ground). Don’t think its the bird as i can’t even get to start the game before stopGame is called.

    My question is, how can i troubleshoot the collisions? Is there some way to output in the console which objects collided together?

     

    Thanks

    Kevin

    #12607

    Lorenz

    Hi Kevin,

    The Boxcollider has a Fixture property. The Fixture has an onBeginContact Signal

    You can do something like this to print the id of the entity you’re colliding with to the console:

    BoxCollider {
        fixture.onBeginContact: {
          // for access of the collided entity and the entityType and entityId:
          var body = other.getBody();
          var collidedEntity = body.target;
          console.debug(collidedEntity.entityId);
        }
    }

    Please let me know if that helps.

    Cheers,

    Lorenz from V-Play

     

    #12608

    Kevin

    Hello

    Thanks for the quick response.

     

    Questions:

    • I put in some code in the Pipe’s fixture.onBeginContact() to only run stopGame() if the item collided with was the player… Is below a good way selectively process collisions? Reason I’m doing this is that the code provided by the tutorial runs stopGame whenever there is any kind of collision, and the lowerpipe is constantly colliding with the ground.
    if (collidedEntity.entityId == "player_0") {
                    scene.stopGame()
                }

     

    • Doing a console.debug(collidedEntity.entityId) as per your provided code, outputs an id value of “player_0” Why is this the case? Based on my code below I was half expecting the output to be “instanceofplayer”

    Player.qml:

    EntityBase {
        id: player
        entityType: "player"
    

     

    main.qml (inside the scene):

        Player {
            id: instanceofplayer
            x: 160
            y: 180
        }
        
    •  Last question: how do i output the entity id of the object experiencing the collision (not the other object)

     

    Thanks so far! Quite helpful and happy with the quick response.

     

    Kevin

     

    #12609

    Lorenz

    Hi Kevin,

    As documented here, the entityid is generated by the EntityManager if you don’t set it explicitely. That explains the “player_0” id :)

    Using the entityid to distinguish between objects you are colliding with is perfectly fine as you proposed. However, I would recommend setting an explicit entityid!

    Alternatively, you can also use the entityType property.

    I hope I was able to clear things up a little. Feel free to ask if you have more questions :)
    Cheers,

    Lorenz from V-Play

     

    #12610

    Kevin

    Thanks Lorenz that helps. Still finding my way around the documentation. Thanks!

Viewing 5 posts - 1 through 5 (of 5 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