Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 1 Support › fixture.onContactEnd is called while object collides with other shape

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4452

    GP

    hy,
    We have an issue with the onContactEnd method. If I drag a shape and it collides with an other shape, everthing works fine but if i drag it first into a shape and then drag it into an other shape the onContactEnd method is called anyway but the dragged shape collides already with an other shape.

     

    This is our used code:

    fixture.onContactChanged: {
                if(!isPlaced) {
                    boxImage.source = "../../img/box_notAllowed.png"; allowedToBuild = false;}}
    
            fixture.onEndContact:  {
                boxImage.source = "../../img/box.png"; allowedToBuild = true}

     

    Also two screenshots:

    First collide with platform: (everthing is fine)

    https://i.imgur.com/ICJ0UdK.jpg

    Then take new shape and drag it first into the platform and then up into the other shape (onContactEnd is called and you can place the shape)

    https://i.imgur.com/9uyzQdG.jpg

    #4456

    Christian
    Felgo Team

    Hi GP, could you please post a full minimal QML demo that shows this problem in more detail?

    Cheers, Chris

    #4457

    GP

    Now here is a little demo project with the same issue:

    Box.qml

    EntityBaseDraggable {
        id: box
        entityType: "rectangle"
        entityId: "box"
    
        colliderComponent: boxCollider
        selectionMouseArea.anchors.fill: rect
        gridSize: 1
        height: 20
        width: 20
        dragOffset: Qt.point(0,0)
        allowedToBuild: true
    
        property alias sWidth: rect.width
        property alias sHeight: rect.height
        property bool isPlaced:false;
    
        showRectangleWhenBuildingNotAllowed: false
    
    
        Rectangle {
            id: rect
            width: 30
            height: 30
            color: "yellow"
        }
    
    
        BoxCollider {
            id: boxCollider
            anchors.fill:rect
            density:100
    
            friction: 1.6
            restitution: 0
    
            fixture.onBeginContact: {
                if(!isPlaced) {
                    rect.color = "red"; allowedToBuild = false;}}
            fixture.onEndContact:  {
                rect.color = "yellow"; allowedToBuild = true}
    
        }
    }

     

    BoxPreview.qml

    BuildEntityButton {
    
        id: ballPreview
        toCreateEntityType: "Box.qml"
        width: 20
        height: 20
    
        property int shapeWidth: 20
        property int shapeHeight: 20
    
        creationProperties: {
    
            "sWidth": shapeWidth,
            "sHeight": shapeHeight,
            "isPlaced":true
        }
    
        onEntityPressed: {
    
             createdEntity.isPlaced = false;
    
         }
    
        Rectangle {
            height: 20
            width: 20
            color: "yellow"
            anchors.fill: parent
        }
    
    }

     

    main.qml

    import VPlay 1.0
    import Box2D 1.0
    import QtQuick 1.1
    
    GameWindow {
        activeScene: scene
        // the size of the Window can be changed at runtime by pressing the number keys 1-6 with QML window active
        // the content of the logical scene size (480x320) gets scaled to the window size based on the scaleMode
        width: 960
        height: 640
    
        EntityManager {
            id: entityManager
            entityContainer: scene
        }
        
        Scene {
            id: scene
    
            Row {
                spacing: 5
                anchors {
                    top: parent.top
                    horizontalCenter: parent.horizontalCenter
                }
    
                BoxPreview{shapeHeight: 50; shapeWidth: 50}
                BoxPreview{shapeHeight: 50; shapeWidth: 50}
                BoxPreview{shapeHeight: 50; shapeWidth: 50}
            }
    
            Rectangle {
                width: 150
                height: 20
                color: "grey"
    
                x:50
                y:200
    
                BoxCollider {
                    anchors.fill: parent
                    bodyType: Body.Static
                }
            }
    
            PhysicsWorld {
                id: physicsWorld
                gravity.y: -9.81
                z: 10
    
    
                updatesPerSecondForPhysics: 60
                velocityIterations: 5
                positionIterations: 5
            }
    
    
        }
    }
    
    

     

    #4458

    Heini

    When i understand you right, you would like to place your entity, when it hasn´t any contact with another entity. I solved a similar problem by adding a counter, that gets incremented in the onBeginContact handler and decremented in the onContactEnd handler. When the counter reaches 0, you can place your entity.
    Something like this:

    BoxCollider{
    ....
      property int ContactCounter: 0
    
      onBeginContact:{
      contactCounter++
      }
    
      onContactEnd{
      --contactCounter;
    
      if (contactCounter===0)
    	rect.color = "yellow"; allowedToBuild = true;
      }
    }
    

    Hope this is what you meaned.

    #4459

    GP

    Hey guybrush,

     

    thank your very much, that was exactly what i needed. I’ve tried the same thing with __collidingObstacles but this doesn’t work. Thanks again! 😉

    #4461

    Christian
    Felgo Team

    Great you found a solution! Thanks Guybrush for helping!

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

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded