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

Get help using Construct 2

Post » Sat Nov 28, 2015 9:23 pm

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.

Help?
Last edited by Hutto on Sun Nov 29, 2015 5:08 am, edited 1 time in total.
B
10
S
4
G
1
Posts: 58
Reputation: 1,420

Post » Sat Nov 28, 2015 10:27 pm

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. :­)
Winstratos on:

Twitter
Facebook
Tumblr
B
12
S
5
G
1
Posts: 23
Reputation: 1,602

Post » Sun Nov 29, 2015 5:08 am

Thanks! I figured there had to be a simpler way than what I was trying to do.
B
10
S
4
G
1
Posts: 58
Reputation: 1,420


Return to How do I....?

Who is online

Users browsing this forum: GunnarWomack, kiugetski and 9 guests