Is there a way to change the size of the physics body depending on the sequence?

In my game, the character will be in different positions whether it’s jumping, shooting, jump-shooting, etc. In some cases, it will require different physics because its position in the image changes. Is there a way to do this using an offset body and change it depending on the animation?

I know you can get the animation sequence by using .sequence, but is it possible to change the physics depending on this as well? Furthermore, is it a good practice and if not are there other solutions?

No.  You cannot resize or post-creation offset physics bodies.

You can either:

  1. Remove and replace the body.  Not great if the body is moving.

  2. Use multi-component bodies and activate/deactivate parts.

  3. … maybe others

The best solution is to compromise.  Choose a body shape that approximates all of the positions or the most important positions of your animations and stick with it.

Note: Many times, you don’t need a body for all animation positions.  i.e. ‘Dead’ animations don’t need a body.  The player is no longer interacting with the environment.  So you can remove the body, deactivate it, or replace it with a simple body to enable ‘falling’ or other physics responses.

Thanks, I’ll do my best to accommodate.

No.  You cannot resize or post-creation offset physics bodies.

You can either:

  1. Remove and replace the body.  Not great if the body is moving.

  2. Use multi-component bodies and activate/deactivate parts.

  3. … maybe others

The best solution is to compromise.  Choose a body shape that approximates all of the positions or the most important positions of your animations and stick with it.

Note: Many times, you don’t need a body for all animation positions.  i.e. ‘Dead’ animations don’t need a body.  The player is no longer interacting with the environment.  So you can remove the body, deactivate it, or replace it with a simple body to enable ‘falling’ or other physics responses.

Thanks, I’ll do my best to accommodate.