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

Forums

OverviewFelgo 1 Support › Physics, Bodies, MoveToPointHelper

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6762

    s4ge

    Hello again,

    today I’m trying to setup a little scene with an actor, an obstacle and a simple floor. all of them are visually and physically represented by rectangles/box colliders. The floor and the obstacle are static bodies. There are two things i want to happen:

     

    1) Everytime, the dynamic actor hits the floor rectangle, the actor should jump (negative y force impulse). This works so far.

    2) Everytime, the screen is touched/clicked somewhere, the force of the actor body should be adjusted the reach this point on the X axis only (the Y force should keep untouched as far as possible). This does not work at all, and a tried alot of configurations to achieve this effect. Here is the code i gave up for now, it includes everything what for the behavior is needed.

     

    import VPlay 1.0
    import QtQuick 1.1
    
    EntityBase {
        id: actor
        entityType: "actor"
    
        width: 50
        height: 80
    
        transformOrigin: Item.TopLeft
    
        MoveToPointHelper {
          id: moveToPointHelper
        }
    
        Rectangle {
            id: rectangle
            anchors.fill: parent
    
            color: "red"
        }
    
        BoxCollider {
            id: boxCollider
    
            anchors.fill: parent
    
            force: Qt.point(moveToPointHelper.outputXAxis * 1, force.y)
    
            fixture.onBeginContact: {
                actor.jump();
            }
        }
    
        function jump(){
            boxCollider.body.applyLinearImpulse(
                boxCollider.body.getWorldVector(Qt.point(0,-300)),
                boxCollider.body.getWorldCenter()
            );
        }
    
        function moveTo(mouseX, mouseY){
            moveToPointHelper.targetPoint = Qt.point(mouseX, actor.y);
        }
    }

     

    • This topic was modified 7 years, 7 months ago by  Christian.
    • This topic was modified 7 years, 7 months ago by  Christian.
    #6777

    Christian
    Felgo Team

    Hi,

    I found your problems, see the comments in-line for an explanation and for a working solution.

    import VPlay 1.0
    import QtQuick 1.1
    
    GameWindow {
    
      Scene {
        id: scene
    
        PhysicsWorld {
    
          gravity.y: -10
        }
    
        MouseArea {
          anchors.fill: parent
          onClicked: {
            actor.moveTo(mouseX, mouseY)
          }
        }
    
    
        EntityBase {
            id: actor
            entityType: "actor"
    
            width: 50
            height: 80
    
            transformOrigin: Item.TopLeft
    
            MoveToPointHelper {
              id: moveToPointHelper
    
              onOutputXAxisChanged: console.debug("outputXAxis changed to:", outputXAxis)
            }
    
            Rectangle {
                id: rectangle
                anchors.fill: parent
    
                color: "red"
            }
    
            BoxCollider {
                id: boxCollider
    
                anchors.fill: parent
    
                // !!! this causes a binding loop! this is the error output:
                // QML BoxCollider: Binding loop detected for property "force"
                // the reason: you are referencing force.y in the property binding
                //force: Qt.point(moveToPointHelper.outputXAxis * 1, force.y)
    
                // with this it works:
                // outputYAxis is needed, because the XAsis of MoveToPointHelper is looking at 0° initally, which means to the right
                // so if the yAxis is 1 this means your entity (looking up) should move right
                force.x: moveToPointHelper.outputYAxis * 1
    
                fixture.onBeginContact: {
                    actor.jump();
                }
            }
    
            function jump(){
                boxCollider.body.applyLinearImpulse(
                    boxCollider.body.getWorldVector(Qt.point(0,-300)),
                    boxCollider.body.getWorldCenter()
                );
            }
    
            function moveTo(mouseX, mouseY){
                moveToPointHelper.targetPoint = Qt.point(mouseX, actor.y);
            }
        }
    
        EntityBase {
          id: floor
    
          width: scene.width
          height: 20
          anchors.bottom: parent.bottom
    
          BoxCollider {
            anchors.fill: parent
            bodyType: Body.Static
          }
          Rectangle {
            anchors.fill: parent
            color: "green"
          }
        }
    
    
      }
    }
    
    

     

    Looks funny already, I’m looking forward to your game! 😉

    Cheers, Chris

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