Groups and Collisions - Player, Boot and Ball

Hi all,

I’ve been playing with Carona the last couple of days and hit the classic newbie problem with groups and collisions.

I’m hoping to open up discussion so us Newbs can understand Display Groups properly and find the best solution to handle Groups and Collisions.

In Physics Notes/Limitations in the developer Guide
    https://docs.coronalabs.com/guide/physics/limitations/index.html
it says

you should not move, scale, or rotate entire display groups independently of each other because of underlying Box2D functionality

Let’s say I have a soccer Player represented by a Knee and a Foot.  It could also be a player, bat ball… etc.
The Player is a Display Group.
The foot has collision detection (static physics).
Both the knee and foot are display objects added to the Player display group.
The Player is also added to the main group.
You can ‘drag’ the player to a desired position and then ‘tap’ to kick the foot.

There has to be a ball, right?  The ball (dynamic) is a display object added to the mainGroup display group where all ‘game’ objects are located.

I’ve created a test project that you can download to check out the code.  
    yes I know it’s a tennis ball and not soccer…
    and what a terrible kick - still to work through that - but collisions first!

I’ve also added ponywolfs visual monitor so start the ‘game’ (either level 1 or level 2) and hit the ‘p’ key to show the physics ‘hybrid’ display.

This setup shows the classic Newbie (me) problem with groups and collisions.  You will see that I have 2 ‘level.lua’ files
level1.lua shows just the boot alone - all works nicely.
level2.lua shows the player group with the boot inserted.  Now, even if you move the player away from the ball, the foot still collides with the ball. ie, it’s local value hasn’t changed - Bummer.

So… what is the best way to utilise the power of grouping for the Player and not loose collision detection?
How do I keep the convenience of my display group (player) and get the boot physics to move with the player?

Looking forward to your discussion.

Using Carona 2017.3184 (2017.12.8)
Running in Carona Simulator (OSX)
 

Yes, some additional print statements gave me this console output.

Jun 23 03:23:24.958 doing drag... Jun 23 03:23:24.958 began - player.touchOffsetX = 165 began - boot.x = 160 Jun 23 03:23:24.959 doing drag... moved - player.x = 0 moved - boot.x = 160 Jun 23 03:23:24.971 doing drag... Jun 23 03:23:24.971 moved - player.x = 0 moved - boot.x = 160 Jun 23 03:23:24.980 doing drag... Jun 23 03:23:24.980 moved - player.x = -1 moved - boot.x = 160 Jun 23 03:23:24.994 doing drag... Jun 23 03:23:24.994 moved - player.x = -3 moved - boot.x = 160 Jun 23 03:23:25.014 doing drag... Jun 23 03:23:25.014 moved - player.x = -6 moved - boot.x = 160

As you can see the player is moving, but the boot isn’t.

Am I best to remove the boot from the player group and place it independently into the mainGroup (with the ball)?

This means that I then need to move the player manually around to keep up with the boot…

Is it possible to place an the boot into 2 groups? ie.  The boot gets added to player AND to mainGroup?

Is there a reason to not just have everything in the same group?

It’s not possible for an object to be in two different groups, but it is possible to nest groups.

Rob

Hi Rob,

Thanks for your reply.

I know that this is a simple example, but I’m thinking into the future when you have a character that has a progress or hit bar above them and perhaps other components. It seems rather long winded to have to keep track of each item and move it manually. 

ie

If the boot is dragged - move the knee accordingly

If the knee is dragged - move the boot accordingly

Maybe this manual update is necessary. 

Objects have the current group structure:

  • mainGroup

     - ball

     - player

           - boot

           - knee

I’ve used this structure so that it’s more object orientated.  Dragging either the boot or knee moves the player - I can call appropriate functions for the player, ie ‘kick’

There must be many structures out there for dealing with multi-object game elements. Most of the example lua code I’ve looked at so far has been only associated with a singe object.  Except for Sticker Knight - which manually positions the skateboard.

Perhaps I would be best to use an invisible object in mainGroup for the foot which is manually controlled based on the player?  This way colliding element/s are in the same group and will register collisions.

Any thoughts?

Yes, some additional print statements gave me this console output.

Jun 23 03:23:24.958 doing drag... Jun 23 03:23:24.958 began - player.touchOffsetX = 165 began - boot.x = 160 Jun 23 03:23:24.959 doing drag... moved - player.x = 0 moved - boot.x = 160 Jun 23 03:23:24.971 doing drag... Jun 23 03:23:24.971 moved - player.x = 0 moved - boot.x = 160 Jun 23 03:23:24.980 doing drag... Jun 23 03:23:24.980 moved - player.x = -1 moved - boot.x = 160 Jun 23 03:23:24.994 doing drag... Jun 23 03:23:24.994 moved - player.x = -3 moved - boot.x = 160 Jun 23 03:23:25.014 doing drag... Jun 23 03:23:25.014 moved - player.x = -6 moved - boot.x = 160

As you can see the player is moving, but the boot isn’t.

Am I best to remove the boot from the player group and place it independently into the mainGroup (with the ball)?

This means that I then need to move the player manually around to keep up with the boot…

Is it possible to place an the boot into 2 groups? ie.  The boot gets added to player AND to mainGroup?

Is there a reason to not just have everything in the same group?

It’s not possible for an object to be in two different groups, but it is possible to nest groups.

Rob

Hi Rob,

Thanks for your reply.

I know that this is a simple example, but I’m thinking into the future when you have a character that has a progress or hit bar above them and perhaps other components. It seems rather long winded to have to keep track of each item and move it manually. 

ie

If the boot is dragged - move the knee accordingly

If the knee is dragged - move the boot accordingly

Maybe this manual update is necessary. 

Objects have the current group structure:

  • mainGroup

     - ball

     - player

           - boot

           - knee

I’ve used this structure so that it’s more object orientated.  Dragging either the boot or knee moves the player - I can call appropriate functions for the player, ie ‘kick’

There must be many structures out there for dealing with multi-object game elements. Most of the example lua code I’ve looked at so far has been only associated with a singe object.  Except for Sticker Knight - which manually positions the skateboard.

Perhaps I would be best to use an invisible object in mainGroup for the foot which is manually controlled based on the player?  This way colliding element/s are in the same group and will register collisions.

Any thoughts?