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

Forums

OverviewFelgo 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 Felgo 3.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
    Felgo 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 5 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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded