How do I shrink a collision box at runtime? [Solved]

0 favourites
  • 3 posts
From the Asset Store
Punch the boxes as hard as you can and crush them all!
  • I have a player sprite and an animation sprite. The player sprite is set to platform and is used for detecting collisions with tilemaps, enemy sprites, etc.

    I want a crouch and slide feature. When the player does this, their collision box is only half as tall.

    I tried changing the size of the player object, but it caused some issues. I then read that the manual says to not resize collision boxes.

    I tried creating splitting it into two sprites: upper half and lower half. I figured I would turn off collision boxes on the top half when they are in a crouched state. I pinned a solid top to the solid platform bottom, but the top does not collide properly with the tilemap. The player can jump too far, and does not hit the ceiling until the bottom collides with it. I tried a few other things but it is either this result, or the top sprite prevents the platform bottom sprite from jumping at all.


  • No need for all this! You should use only one collision box.

    The manual says that because changing the box too much may cause issues like going through walls and that messes all the engine, but you can make it in a controlled way.

    What I do is:

    Make two animations for the collision box, one used for all sprite animations, and a shorter one for crouching and sliding. Make sure the origin is perfectly positioned so the box won't move when you change animations. I also think the best shape for it is a perfect rectangle.

    Let the player crouch without limitations, but whenever your character gets up, there's a condition checking if its overlapping the tilemaps. I can be done this way:

    -If player is not holding the crouch buttom: change the collision box animation to standing

    -Collision box is overlapping tilemap: change the collision box animation back to crouching

    There's no problem in forcing the animation to stand even when there's the possibility of it going through walls, as long as you change it to it's original state when it does. It's a good way for checking. :­)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks! I figured there had to be a simpler way than what I was trying to do.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)