Forums

OverviewV-Play 2 Support (Qt 5) › Issue with MoveToPointHelper moving only right

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

    Kool

    Hi guys,

    I’m using the MoveToPointHelper to move an object towards the player position, on the x-axis only. The y is handled elsewhere. My issue is that the outputXAxis property of the helper only ever outputs +1, so I’ve a feeling there’s some misuse on my end.

    Here’s an example game that demonstrates the issues (use left/right keyboard arrow keys to move around):

    import VPlay 2.0
    import QtQuick 2.0
    
    GameWindow {
        id: gameWindow
    
        activeScene: scene
    
        screenWidth: 960
        screenHeight: 640
    
        EntityManager {
            id: entityManager
            // entities shall only be created in the gameScene
            entityContainer: scene
        }
    
        Scene {
            id: scene
    
            // the "logical size" - the scene content is auto-scaled to match the GameWindow size
            width: 480
            height: 320
    
            Keys.forwardTo: controller
    
            PhysicsWorld {
                debugDrawVisible: true
            }
    
            Rectangle {
                color: "black"
                anchors.fill: parent
            }
    
            EntityBase {
                id: player
                width: 25
                height: 25
                y: 200
                x: scene.width/2 - player.width
    
                TwoAxisController {
                    id: controller
                }
    
                Rectangle {
                    anchors.fill: parent
                    color: "red"
                }
    
                BoxCollider {
                    id: collider
                    bodyType: Body.Dynamic
                    linearVelocity: Qt.point(controller.xAxis * 1000, 0)
                }
            }
    
            EntityBase {
                id: enemy
                width: 25
                height: 25
                x: 0
                y: 50
    
                Rectangle {
                    anchors.fill: parent
                    color: "white"
                }
    
                MoveToPointHelper {
                    id: moveToPointHelper
                    targetObject: player
                    onOutputXAxisChanged: console.debug("Move P Helper X:", outputXAxis)
                }
    
                MovementAnimation {
                    id: followAnimation
                    target: parent
                    property: "x"
                    velocity: 30 * moveToPointHelper.outputXAxis
                    running: true
                }
            }
        }
    }
    

    You’ll see that the enemy entity only ever moves to the right.

    Any ideas where the issue is

    #13604

    Günther
    V-Play Team

    Hi Kool!

    I can reproduce the problem, we will have a closer look why this is happening. In the meantime, you can use the following workaround to achieve the desired behavior:

                MoveToPointHelper {
                    id: moveToPointHelper
                    targetObject: player
                    onOutputXChanged: console.debug("Move P Helper X:", outputX)
                    property int outputX: Math.round(absoluteRotationDifference) == 90 ? 0 : (absoluteRotationDifference > 90 ? -1 : 1)
                }
    
                MovementAnimation {
                    id: followAnimation
                    target: parent
                    property: "x"
                    velocity: 30 * moveToPointHelper.outputX
                    running: true
                }

    The absoluteRotationDifference property can be used to create a custom outputX property similar to the outputXAxis property.

    Cheers,
    Günther

     

    • This reply was modified 2 years, 1 month ago by  GT.
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