Problems with keeping character centered on your hitbox

#1

I’m using a spritesheet that has multiple images depending on the character’s movement (in this case a donkey) and I want to center the character on your hitbox. The problem is that whenever I try to change in size, the character never gets centered because what is changed is just the left side of the hitbox, which usually just gets more or less wide as I change the dimensions. I intended to be able to change the dimensions of the character’s hitbox, but at the same time manage to keep the character centered for movement purposes. I send the image with the center problem and also the spritesheet where we can see all the images that make reference to the different movements of the character.

burro

burro

#2

Try to use setSize() and setOffset() on the body to adjust the hitbox manually.

https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Body.html

#3

Thank you, it work’s!