Character head detached from body

Hi guys, I could use some help here. Been trying all kinds of methods to fix this bug but no luck.

I have a game character which consists of 2 parts; a head and a body. I combined them together using a runtime event listener.

It works well but for some reason, once I pause my game and resume, the head starts to ‘detach’ from the body. It’s obvious when the character is flying left or right. As you can see below, the head is slightly to the left instead of being in the center.

headbodybug.png

Below are the codes I used to create the in-game Pause function 

function gamePaused() Runtime:removeEventListener("accelerometer", onTilt) Runtime:removeEventListener("enterFrame", playerMove) Runtime:removeEventListener("touch", touchScreen) Runtime:removeEventListener( "tap", onExclusiveTap ) physics.pause() end

The event listener used to attach both head and body isn’t stopped even when the game is paused. At this point, I have no idea what’s causing this bug.

Any help is very much appreciated. Thanks!

You seem to be using physics, right? If so why don’t you use joints to keep the bodies together? Sounds like a weld joint could work.

Also, is there any need to have two separate bodies? Could the player just be one whole image with a custom physics body with multiple parts so you can differentiate between which part was hit?

Just throwing out some guesstimate suggestions :slight_smile:

From what i gather, it sounds like your keeping them together via a runtime listener?

Also i would also suggest that removing the event listeners on pause is a little over the top. I would use a finite state machine along with a boolean flag to control whether the game is paused or not, and if it is, then you just don’t execute the relative code within your runtime/touch listeners etc.

Hope this helps.

@Gremlin 

I forgot to mention that I did try using weld joint. The result was somehow the same (which was weird)  :frowning:

The reason for the separation is because the player can obtain new hats for the character. So rather than having to create animation for each new hat, it’s more optimized to just animate the body and ‘attach’ the character’s head to it  :slight_smile:

I will try the boolean flag suggestions and see if it works. Thanks. 

I googled around and saw someone set this physics property and it fixed the seperation issues with joints:

physics.setContinuous( false )

It could cause issues with objects moving at really really fast speeds (like bullets) but i would check out the thread to see if turning this off would have any adverse effects for your game.

Thread: http://forums.coronalabs.com/topic/2232-pivot-joints-and-apparent-elasticity/

(It says pivot joints but i saw similar issues with all joint types posted around various forums and heck, it’s worth a try) i haven’t used joints in a while so I can’t tell you first hand if this will help you or not. But give it a go all the same.

Let me know if it helps.

Awesome!  :)  Can’t believe I didn’t manage to find that thread. I must have googled with the wrong keywords.

Will give this a go. Thanks!

Unfortunately that didn’t seem to work for me. After I pause and unpause the game, the ‘elastic’ effect kicked.

I didn’t pause the physics so I’m really confused as to why I’m getting this bug.

You seem to be using physics, right? If so why don’t you use joints to keep the bodies together? Sounds like a weld joint could work.

Also, is there any need to have two separate bodies? Could the player just be one whole image with a custom physics body with multiple parts so you can differentiate between which part was hit?

Just throwing out some guesstimate suggestions :slight_smile:

From what i gather, it sounds like your keeping them together via a runtime listener?

Also i would also suggest that removing the event listeners on pause is a little over the top. I would use a finite state machine along with a boolean flag to control whether the game is paused or not, and if it is, then you just don’t execute the relative code within your runtime/touch listeners etc.

Hope this helps.

@Gremlin 

I forgot to mention that I did try using weld joint. The result was somehow the same (which was weird)  :frowning:

The reason for the separation is because the player can obtain new hats for the character. So rather than having to create animation for each new hat, it’s more optimized to just animate the body and ‘attach’ the character’s head to it  :slight_smile:

I will try the boolean flag suggestions and see if it works. Thanks. 

I googled around and saw someone set this physics property and it fixed the seperation issues with joints:

physics.setContinuous( false )

It could cause issues with objects moving at really really fast speeds (like bullets) but i would check out the thread to see if turning this off would have any adverse effects for your game.

Thread: http://forums.coronalabs.com/topic/2232-pivot-joints-and-apparent-elasticity/

(It says pivot joints but i saw similar issues with all joint types posted around various forums and heck, it’s worth a try) i haven’t used joints in a while so I can’t tell you first hand if this will help you or not. But give it a go all the same.

Let me know if it helps.

Awesome!  :)  Can’t believe I didn’t manage to find that thread. I must have googled with the wrong keywords.

Will give this a go. Thanks!

Unfortunately that didn’t seem to work for me. After I pause and unpause the game, the ‘elastic’ effect kicked.

I didn’t pause the physics so I’m really confused as to why I’m getting this bug.