Forums

OverviewV-Play 1 Support › BoxCollider

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6460

    kitKat

    Hi!

     

    Is there any way to check at which length an entity collides with another? (in our game, they shouldn’t be deleted if they collide at an edge, just if they collide at the whole border of a side).

    #6462

    Alex
    V-Play Team

    Hi kitKat,

    this is not that trivial as far as i know, but I think i can show you everything you need to solve your problem.

    First you will need to find out the direction of the collision, this information is stored in the “contactNormal” vector which is available within the “fixture.onBeginContact:” signal. You can find a code sample in Ball.qml of the VPong demo game.

    If you know from which side the entity is approaching the target, you can compare the x and y values to find out the “length” of the collision.

    Let me know if this helped you. Also if you produce some nice code that could help other developers, feel free to post it here 😀

    Cheers,
    Alex

    #6482

    kitKat

    Hi!

     

    Finally i got it!

    Here’s the code:

     var normalX = contactNormal.x;
                    var normalY = contactNormal.y;
    
                    console.debug("X: ", normalX, ", Y: ", normalY);
    
    
                    if (normalX === 1) { //collision from left
                        
                        //check if same height (from the side)!
                        if (component.parent.y === parent.y) {
                            removeEntity();
                        }
                    }
                    else if (normalX === -1) { //collision from right
                       
                        //check if same height (from the side)!
                        if (component.parent.y === parent.y) {
                            removeEntity();
                        }
                    }
                    else if (normalY === 1) { //collision from above
                       
                        //check if same x-coordinates (from above)
                        if (component.parent.x === parent.x) {
                            removeEntity();
                        }
                    }
                    else if (normalY === -1) { //collision from under
                        
                        //check if same x-coordinates!
                        if (component.parent.x === parent.x) {
                            removeEntity();
                        }
                    }

     

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