Forums

OverviewV-Play 1 Support › How to check if there is an entity at position x y?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6500

    Christine

    Hello,

    how can I check if there is an entity at a certain position in the scene with the x y coordinates or the row and column of a grid?

    #6503

    Alex
    V-Play Team

    Hi,

    if your entities are having colliders, the easiest way would be:

    var selectedBody = physicsWorld.bodyAt(Qt.point(x, y));
    if(selectedBody) {
      // found something!
      var entity = selectedBody.parent.parent;
      console.debug(entity.entityType);
    }

    The parent of the Box2D body that you select is the Collider, the parent of the Collider will be the entity whose properties and function are then accessible for you.

    Cheers,
    Alex

     

     

    #6537

    Christine

    Thank you!

    What if there are more entities at that point? Is there a way to get an array or a list of them all?

    Best regards,

    Scarlet

    #6541

    Christian
    V-Play Team

    Hi Scarlet,

    bodyAt only returns the first object found. What is your use case for having multiple bodies at one position?

    Cheers, Chris

    #6565

    Christine

    I need it because the behaviour of the player character depends on the entities at some positions around it.

    #6567

    Christine

    Or is there a Way to get the status of the BoxCollider and the entity it is actually colliding with? I tried to use the BoxCollider, but to control of the player we use the joystick and if the user presses left again after the onContact while the player has still contact with the entity, the player character runs over the entity. So I tried the other way with checking the points, but that only works if the size of the entity is used and if I use the size of the BoxCollider I get the player entity and not the entity of the wall. So a list would be nice to check if there is any entity at that point which the player is not allowed to pass.

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