Forums

OverviewV-Play 1 Support › Disable Bounce on BoxCollider

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4252

    phil.jahoda

    Hi.

    In our game, its the players task to shoot arrows to pop baloons. Therefore I have to check when the arrow hits a baloon.

    I do that within the fixture.onBeginContact(….) method where I then make the baloon disappear.

    The problem is, that as soon as the arrow hits the baloon, it bounces from it. But that should not happen because I want the arrow to continue flying its original direction. How can I stop it from bouncing of a baloon?

    As our pysicsworld also uses gravity.y, I have to make the Baloon BoxCollider BodyType.Static to keep it from falling.

    I already tried setting vairous properties to zero, it didnt help.

    #4253

    phil.jahoda

    Here is my Baloon.qml, I am sorry, the code tag does not seem to work.

    import QtQuick 1.1
    import Box2D 1.0
    import VPlay 1.0
    import "../particles"
    
    EntityBase {
      id: entity
      width: 20
      height: 25
      entityType: "baloon"
      
      property alias baloonImg: baloonImg
      
      BoxCollider {
        id: boxCollider
        bodyType: Body.Static
        width: baloonImg.width
        height: baloonImg.height
        
        // like this, an offset for the rotation could be set which is only applied for the collider, not for the entity!
        // rotation: 45
        
        anchors.centerIn: parent
        
        // set friction between 0 and 1
        fixture.friction: 0
        // restitution is bounciness
        fixture.restitution: 0
        // if you want to make objects fall faster, increase gravity (and not density)
        // with higher density, the player behaves differently at collisions as it is heavier
        fixture.density: 0
        
        fixture.onBeginContact: {
          
          var fixture = other;
          var body = other.parent;
          var component = other.parent.parent;
          var collidedEntityType = component.owningEntity.entityType;
          
          var collidingType = component.owningEntity.entityType;
          // play the collision sound when the box collides with anything, but not if the sound is already playing
          if(scene.collisionSoundsEnabled && !collisionSound.playing)
            collisionSound.play();
          
          if(scene.particlesEnabled)
            collisionParticleEffect.start();
          
          if(collidingType === "dartarrow" ) {
            entity.removeEntity();
            
            return;
          }
        }
      }
      
      Image {
        id: baloonImg
        source: "../img/baloon_green.png"
        // this is the size compared to the scene size (480x320) - it will automatically be scaled when the window size is bigger than the scene
        // the image will automatically be scaled to this size
        width: 20
        height: 25
        
        // this is required to have the center in the middle of the enity and not the top left point as origin of the image
        anchors.centerIn: boxCollider
      }
      
      // gets played at a collision
      Sound {
        id: collisionSound
        source: "../snd/boxCollision.wav"
      }
      
      // this particle effect is played when colliding with an obstacle
      SmokeParticles {
        id: collisionParticleEffect
      }
    }
    #4259

    Christian
    V-Play Team

    Hi,

    we are sorry for inconveniences with the Code button and working on a fix for it!

    Regarding your Box2D question:

    You could use the sensor property of BoxCollider for your use-case.By setting it to true, you still get notified when a collision occurs, but the other bodies do not physically react to the collision. Does that solve your problem?

     

    Cheers,

    Chris

    #4266

    phil.jahoda

    I do not completely understand why, but yes this solves my problem.

    Thank you very much!

    #4267

    Christian
    V-Play Team

    Hi again,

    from the Box2D manual section 6.3 about sensors which is available here:

    Sometimes game logic needs to know when two fixtures overlap yet there should be no collision response. This is done by using sensors. A sensor is a fixture that detects collision but does not produce a response.

    Maybe that explains the topic best.

    Cheers, Chris

Viewing 5 posts - 1 through 5 (of 5 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