Forums

OverviewV-Play 1 Support › Path movement with dynamic input

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

    PanflamCutie

    Dear V-Playteam,

    I want to move an entity to an dynamically created position. The starting point of the entity is set manually, while the other positions are created dynamically by calculation depending on the actual position (and the obstacles in the way of the entity). So if the entity is moved one field in the grid (positions defined by x: column*gridSize and y: row*gridSize – row[0, 8] | column[0, 12]) the goal position should be recalculated (even if the actual goal position wasn’t reached yet).

     

    I’ve tried to realize this with the “Path Movement”, by setting the loop to infinte (loops: Animation.Infinite) and creating the goal point dynamically. However, I didn’t know how to set the start position without repeating it in the loop to and how to reset the position even if the entity has only moved one field (without reaching  the entered waypoint) – furthermore the movement is always restarting with the first position if any one of the waypoints is changed.

    I hope you can help me in this matter and I’m looking forward to a quick answer.

     

    Best regards,
    PanflamCutie

     

    #6564

    PanflamCutie

    How can a entity be moved by using dynamically generated input (Qt.point)?

    #6572

    Alex
    V-Play Team

    Hi,

    do you recalculate the goal every time the entity has moved ONE field in the grid? Then the first thing that comes to my mind is using a MovementAnimation like this:

    1. calculate the goal

    2. calculate the movement of one field in the grid towards the goal

    3. pass this values to the MovementAnimation

    4. start the MovementAnimation

    5. when the animation finished, repeat these steps

    Cheers,
    Alex

    #6574

    PanflamCutie

    Hi,

    I kind of already realized it with Path Movement. It looks like this:

    property int xPoint: 1
        property int yPoint: 0
        property int actualPosX: column*gridSize;
        property int actualPosY: row*gridSize;
    
        PathMovement {
            velocity: 100 // Geschwindigkeit
            rotationAnimationDuration: 200
               waypoints: [
                   { x: actualPosX, y: actualPosY},
                   { x: xPoint*gridSize, y: yPoint*gridSize}//xPoint(column)  yPoint(row)
               ]
    
               onWaypointReached: { // add logic!!!!!
                   column = xPoint
                   row = yPoint
    
                   chooseDirection()
    
                   move()
               }
    
               onPathCompleted: {
                   start()
               }
           }

    It works quite well (I still must add some conditions, whether if the entity is allowed to get to this field or not), but I have a problem now with the rotation, because its rotation-origin is at the left-down-corner (I think it’s that one), but it should turn with its center as origin.

     

    Best regards,
    PanflamCutie

    #6580

    PanflamCutie

    Dear Alex,

    I tried to revite my code, so that it works with MovementAnimation (as you requested).

    I’ve got two functions, which are responsible for calculating the next direction to take, but I don’t know where to invoke them (first).

    Furthermore, is there a way to check if the entity has reached the “next field” without calculating the “goal field” to which the values of x and y of the entity must be compared to?

        function calculateTheGoal() {
            leftWay = true
            rightWay = true
            upWay = true
            downWay = true
    
            // checking for border
            if(column === 0) {
                leftWay = false
            }
            if (column === 12) {
                rightWay = false
            }
            if (row === 0) {
                upWay = false
            }
            if (row === 8) {
                downWay = false
            }
        }
    
        property bool done: false
        property int xPoint: 0
        property int yPoint: 0
    //    property point nextWay
        function move() {
            calculateTheGoal()
            while (done === false) {
                randomNumber = utils.generateRandomValueBetween(1, 4)
                console.debug(randomNumber)
                switch (randomNumber) {
                    case 1:
                        if (upWay) {
                            //nextWay = Qt.point(0, -1)
                            xPoint = 0
                            yPoint = -1
                            done = true
                        }
                        break;
                    case 2:
                        if (rightWay) {
    //                        nextWay = Qt.point(1, 0)
                            xPoint = 1
                            yPoint = 0
                            done = true;
                        }
                        break;
                    case 3:
                        if (downWay) {
    //                        nextWay = Qt.point(0, 1)
                            xPoint = 0
                            yPoint = 1
                            done = true;
                        }
                        break;
                    case 4:
                        if (leftWay) {
    //                        nextWay = Qt.point(-1, 0)
                            xPoint = -1
                            yPoint = 0
                            done = true;
                        }
                        break;
                }
            }
            movement.running = true
            done = false
        }

     

    MovementAnimation {
    //        1. calculate the goal
    //        2. calculate the movement of one field in the grid towards the goal
    //        3. pass this values to the MovementAnimation
    //        4. start the MovementAnimation
    //        5. when the animation finished, repeat these steps
    id: movement
            target: parent
            property: "pos"
    
            velocity: Qt.point(xPoint, yPoint)
            running: true
    
    
            onRunningChanged: {
    
                move()
    
            }
    
        }

    Thanks in advance and best regards,

    PanflamCutie

    #6583

    Alex
    V-Play Team

    Hi,

    you can set the goal position as limit of the MovementAnimation, then onLimitReached will be emitted when your move is done.

    Alternatively you can also use a PropertyAnimation like this:

    PropertyAnimation {
        id: moveHorizontal
        target: yourEntity
        properties: "x"
        to: whateverYouCalculatedAsGoalValue
        duration: 1000 // one second
        onCompleted: {
          // maybe check if the vertical movement has also finished in case you can move diagonal. If not, just do nothing and let the other animation trigger the next move when it finishes.
          // If yes, call you calculation method and start the animations again
          // the same applies for vertical movement
        }
      }

    Cheers,
    Alex

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