Forums

OverviewV-Play 2 Support (Qt 5)physics acceleration object over time › Reply To: physics acceleration object over time

OverviewV-Play 2 Support (Qt 5)physics acceleration object over time › Reply To: physics acceleration object over time
#11269

Alex
V-Play Team

Oh well, the pong tutorial is outdated and not yet part of the official documentation at the moment.

The problem that you are facing in that old tutorial is, the ball is not really bouncing with pure physics, but instead on every collision it is stopped and the new velocity is calculated and applied to the ball. So you won’t see the effect of this small acceleration, because the next collision is happening and again the ball is stopped and the new velocity is calculated, always with the speed variable that is set to a fixed value of 400. I added a small project which shows the acceleration I suggested.

import VPlay 2.0
import QtQuick 2.0

GameWindow {
  id: gameWindow
  activeScene: scene
  width: 960
  height: 640

  EntityManager {
    entityContainer: scene
  }

  Component.onCompleted: {
    ball.collider.applyLinearImpulse(Qt.point(70,34));
  }

  Scene {
    id: scene
    width: 480
    height: 320

    PhysicsWorld {

    }

    BoxCollider {
      width: 10
      height: parent.height
      bodyType: Body.Static
      anchors.right: parent.left
    }
    BoxCollider {
      width: 10
      height: parent.height
      bodyType: Body.Static
      anchors.left: parent.right
    }
    BoxCollider {
      width: parent.width
      height: 10
      bodyType: Body.Static
      anchors.bottom: parent.top
    }
    BoxCollider {
      width: parent.width
      height: 10
      bodyType: Body.Static
      anchors.top: parent.bottom
    }

    EntityBase {
      id: ball
      x: 50
      y: 50
      property alias collider: collider
      Rectangle {
        color: "#f00"
        width: 10
        height: 10
        radius: 5
        anchors.centerIn: parent
      }

      CircleCollider {
        id: collider
        radius: 5
        restitution: 1
        friction: 0
        bullet: true
        force: Qt.point(linearVelocity.x/10,linearVelocity.y/10)
        anchors.centerIn: parent
      }
    }
  }
}

In the pong tutorial, you could increase the value of the speed variable on every collision and this would make the ball faster.

Cheers,
Alex

  • This reply was modified 2 years, 9 months ago by  Alex.

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