How would I solve this problem?

I believe I would have to find the shortest distance between the two collisions and use the collision with the shortest distance. However, I don’t know how to do this because the collisions don’t have names. This is using a tile map.

Turn off rotation might be the first step

Turning off rotation is the same thing as what Niantic did to Pokemon GO’s tracking feature. (It’s a tad buggy, lets disable it entirely instead of fixing it!)

The bug is caused because it’s touching the slope one frame, and then touching the floor another. Turning off rotation wouldn’t fix the bug, it’d just not be visible anymore.

You’re right. That’s why I said it was the first step.

Might this help? http://www.defold.com/manuals/physics/#_resolving_kinematic_collisions

1 Like

I admit my stupidity as I feel this is the right direction however I have no idea at the same time.

I’m no expert either, but here’s a potential solution that comes to mind:

  • calculate the intersection of the two slope-lines
  • calculate X-distance from center of sprite to slopes intersection
  • if it’s positive, use the left slope. if it’s negative, use the right one

If each terrain tile is four of those smaller green squares I see, and you’re getting them individually in the collisions, then you can probably calculate the intersection point by looking for a shared corner point between tiles (in world coordinates). Then you can compare the character’s x position to the x position of the shared point, and choose which collision normal to base your character rotation on that way.

@Mathias_Westerdahl, did you encounter similar problems when you experimented with slopes, and if so, what was your solution?

Well, personally, I’d set the “lock rotation”, but that might be due to the fact I’m used to having a round shape at the bottom of my characters. In 3D games, a capsule is very common, but since Box2D doesn’t have one, I used two spheres and a box. A round shape at the bottom will help traversing smaller obstacles, should there be any. also, it fits more with the rotation motion of the legs of my character. And, it will get a lot easier to resolve collisions :slight_smile:

Then, I experienced problems with switching from box to sphere for my kinematic body (It falls asleep every 33 frames):

And, even if I ignored that, I found other problems with normals in tilemaps:

FWIW, my plan is to replace my kinematic body with a dynamic one, and see if I can get the platformer behavior I want anyways. Currently, the kinematic body doesn’t have any velocity, so it doesn’t affect other objects the way I’d like.
As for the tilemap normal issue, it’s not very high priority right now, but if it happens to you please let us know!

1 Like

I’ve had a chance to read these but I’ve been distracted as of late and unable to actually put them into practice. I’ll update this post once I have had time to combat this problem. Hopefully with a resolution.

I’ve done some slope experiments and have found that any tiny glitch in the physics (or just 2 joined corners) messes up things bad. Going with a sphere helps but using ray casts to anchor the character with ground is what I would try first (depending on use case).