[SOLVED] How do I handle collisions with a wall?

Hi guys!
I’m sorry to bother you with that but I can’t seem to get this bug fixed…
To better have a look and because a picture is often worth a thousand words, here is a little video : https://streamable.com/cnsii1

To give you more details : the red and orange square have platform behavior
My character is setup with “states” and here, the RUN state alternates with the FALL state when the character collides with a wall smaller or equal to 2 squares.

Another info (I don’t know if it’s relevant) : the character and the ground/wall are on 2 different layers…

I thought about the collision masks, I tried to fidle with them but didn’t get any result…I don’t really know what the rule of thumb is when creating custom collision masks (except for the convex constraint).

Well, if you have any ideas…

As for the logic, here is my very simple logic for the character states, it might be flawed…

The collision mask for the RUN animation looks like so :

It’s the collision boxes that are causing the problem. The collision box for the run animation is from feet to head. For the fall animation, it’s from waist to head. So when the character is in fall mode, it does so until the hui box collides with the red square.

In this screen shot, you can clearly see the collision box outline on the character, and it’s still a wee gap to the red platform (indicated by the red arrow I included):


The easiest fix is to change the fall animation hit box to be from feet to head, so it’s the same as the run animation hit bx

@MrMen hummm…Thanks! I’ll try that right away!

A question though : I don’t really understand why the collision causes the character to “fall”…

There is no collision with the red blocks and so the platformer behaviour will drop the object down until it does collide.

I tried what you rightly suggested but it doesn’t really seem to work…Here is a video which I slowed down where you can see that the character goes through the different states RUN → FALL → IDLE when I run against the wall.

Ok, so the Run Collision Mask should be the culprit?

Alright, to avoid any issue, I had to redo all my collision boxes : they are now a bit bigger than the character… for example :


I wonder if that will cause trouble further down the line…

It’s the base of the hit box that matters. That’s how the platform behavior knows the player is on the ground. If they don’t match it causes 2 problems. First, it will drop and then if the other hit box is inside the platform it will force the objects apart, sometimes violently with a random force.

You can align the collision around the image just make sure the hit box and origin points align.

Since there’s events for isFalling it doesn’t know the difference between an intentional fall and one caused by the changing hit boxes or origin points.

1 Like

Thanks @Keith_1357 ! I’m not sure I understood everything you said, especially in the first paragraph! :smiley: What do you mean when you say : “If they don’t match’”? When you say “they” , do you mean the “ground Collision mask” and the “Object collision mask”?

Oh yeah…Didn’t think about the points…I didn’t modify them…I should give that a try tomorrow!

Thanks again for the explanations!
By the way : is there some broad guidelines I should follow to set up those collision masks?

When I said they I was referring to the different points and hit boxes on different animations.

@Keith_1357 Sorry, a follow-up question : when you say : “just make sure the hit box and origin points align”. What do you mean?
Must all the animations of a character have the same Origin point? (I guess so…)
Or do you mean, within the same animation, the origin point must stay the same but can change across the different animations?

Sorry, I’m a bit confused by this!

Aligning the bottom edge perfectly only really matters with things like the platform behavior because the behavior determines the placement of the object based on the mask and the points.

The origin point is more like an offset. Moving the point moves the image in relationship to the the X, Y. The image will move up, down, left and right based on the point along with the mask.

The collisions box or hit box or mask or whatever you want to call is used to detect collision. It’s normally roughly the same size as the image but there’s nothing saying it can’t be larger than the drawn part or smaller.

The main thing is the combination of the point and the collision mask needs to match on the bottom otherwise when you switch frames or animations it would change the position of the collision mask.

It’s easier to keep everything aligned if they share the same point and image size. By image size I mean the file or canvas size not the actual image or pixels. For a platform game, you just want to draw everything along the bottom of the canvas. Any empty part should be on the top. That way you can align the bottom edge and if needed move the top points.

@Keith_1357 Thank you very much for the detailed clarifications! It all makes sense and I’ll have to come back to your post a few times to fully grasp what you’re saying. I’ll meditate on that! :wink:
Anyways, as regards to my “bug”, I realigned the Origin points of the animations of my character. They are now all at the same place on all the animations and as far as I can tell, the bug we could see on the video I posted no longer exist.

So thanks again and I can “solved” this thread!!

1 Like