Forums

OverviewV-Play 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 4 years, 9 months ago.
    • This topic was modified 4 years, 9 months ago.
    #6777

    Christian
    V-Play 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.

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