Forums

OverviewV-Play 2 Support (Qt 5) › (Free) Particles influenced by entity rotation

Tagged: 

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

    Elisabeth

    Hello everyone,

     

    when rotating an entity which includes a particle emitter, the movement of the emitted particles is influenced by the rotation of the entity. The effect becomes more obvious for fast rotation velocities. Here is some code which showcases the behaviour:

     

    main.qml:

    import VPlay 2.0
    import QtQuick 2.0
    
    GameWindow {
      id: gameWindow
      activeScene: scene
      width: 960
      height: 640
    
      EntityManager {
        id: entityManager
        entityContainer: scene
      }
    
      Scene {
        id: scene
        width: 480
        height: 320
    
        Item{
          BoxCollider {
        	  id: fix
        	  x: scene.width / 2
        	  y: scene.height / 2
        	  bodyType: Body.Static
          }
    
          ParticleEmitter {
          	  x: scene.width/2
          	  y: scene.height/2
          	  jointBody: fix.body
          }
    
          PhysicsWorld {
            id: world
            updatesPerSecondForPhysics: 60
            gravity.y: 0.0
    
            velocityIterations: 5
            positionIterations: 5
    
            running: true
          }
        }
      }// scene
    }

    ParticleEmitter.qml:

    import QtQuick 2.0
    import VPlay 2.0
    
    EntityBase {
      id: root
      width: 40
      height: 10
      //transformOrigin: Item.TopLeft
    
      property variant jointBody: null
      property alias body: collider.body
    
      BoxCollider {
        id: collider
        width: root.width
        height: root.height
        x: -root.width / 2
        y: -root.height / 2
    
        density: 0.05
    
        torque: {
          0.01;
        }
     
        Rectangle {
          id: rect
          anchors.fill: parent
          color: "red"
        }
      }
    
      RevoluteJoint {
        id: joint
        bodyA: body
        bodyB: jointBody
        localAnchorA: Qt.point(-20, 0)
        world: physicsWorld
      }
    
      Particles{
        id: particles
        x: 20
      }
    }
    

    Particles.qml

    import QtQuick 2.0
    import VPlay 2.0
    
    ParticleVPlay {
      id: particle
      fileName: "FireParticle.json"
    
      startParticleSize: 10
      startParticleSizeVariance: 0
      finishParticleSize: 10
      finishParticleSizeVariance: 0
      particleLifespan: 3
    
      positionType: ParticleVPlayBase.Free
    
      // start when finished loading
      autoStart: true
    }

     

    For the particles “FireParticle.json” and “particleFire.png” are used which are included in the ParticleEditor demo.

     

    Any hint is highly appreciated!

    Cheers,

    Thomas

    #8076

    Alex
    V-Play Team

    Hi Thomas,

    we can reproduce the issue and are working on a fix for this. The problem is the following: For the Free positionType, the particle is internally compensating the movement of the parent. Now in your use case, the parent is only rotation, so the particle is taking care of this rotation change to compensate it. This would work fine if the particle would be emitted in the center of the rotating parent. Now that the particle is NOT in the center of the parent, but sitting on the edge instead, it still only sees the rotation change of the parent, and not that the particle itself is effectively also changing its x and y coordinates on the screen, due to sitting on the edge of the rotating parent. Therefore the exact movement of the particle emitter is not fully compensated.

    A workaround for you would be to wrap the particle in a parent item that performs the movement by really changing its x and y values. This could look like this:
    main.qml

    // ...      
          ParticleEmitter {
              id: particleEmitter
              x: scene.width/2
              y: scene.height/2
              jointBody: fix.body
          }
    
          Item {
            x: particleEmitter.x + particleEmitter.width/2 * Math.cos(particleEmitter.rotation*Math.PI/180)
            y: particleEmitter.y + particleEmitter.width/2 * Math.sin(particleEmitter.rotation*Math.PI/180)
            rotation: particleEmitter.rotation
            Particles {
              id: particles
            }
          }
    // ...

    If you want to try standard Qt5 Particles instead, this is a nice set of tutorials, also containing one for Particles: http://qmlbook.org/ch08/index.html

    Sorry for the inconvenience.

    Cheers,
    Alex

    • This reply was modified 4 years, 2 months ago by  Alex.
    • This reply was modified 4 years, 2 months ago by  Alex.
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