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
#11285

Alex
V-Play Team

So I added a suggestion for the rotation, in this case it’s just a property binding on the velocity property of a MovementAnimation that is constantly rotating the rectangle of the entity, so it rotates in the direction it is traveling, and also rotates faster if the ball travels faster (at least in x direction):

import VPlay 2.0
import QtQuick 2.0

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

  EntityManager {
    id: entityManager
    entityContainer: scene
  }

  Component.onCompleted: {
    ball.collider.applyLinearImpulse(Qt.point(50,50), ball.collider.body.getWorldCenter());
  }

  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 {
        id: rect
        color: "#f00"
        width: 10
        height: 10
      }

      MovementAnimation {
        target: rect
        property: "rotation"
        velocity: collider.linearVelocity.x // this is the property binding to alter the rotation
        running: true
      }

      CircleCollider {
        id: collider
        radius: 5
        restitution: 1
        friction: 0
        bullet: true
        force: Qt.point(linearVelocity.x/10,linearVelocity.y/10)
        fixture.onEndContact: {
          // you could also calculate the rotation velocity here, after a contact, based on any values you prefer
          // this would give you even more control
        }
      }
    }
  }
}

Cheers,
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