Geometry handling setting x velocity to 0

hey, this is my first attempt at making a game using defold so i copy pasted the geometry handling function.

everything works fine so far except from my sprite walking animation keeps glitching out and resetting every 1-2 frames when i try to walk. the Idling animation is fine when substituted for the walking animation. it loops perfectly.

i found the problem in the geometry handling function specifically in:

this is what the values are when the game is running:
image

it seems that when the program removes the component, it sets the x velocity to 0 and thus my character animation stops and starts.

any help is appreciated thanks

1 Like

Welcome!
I don’t quite understand why do you need such check in the game. A larger portion of code might help.
Or even better - upload the entire project and I’ll take a look.

hey, thanks for the quick reply. i’m not actually sure where to look to find the project file to upload.

Just zip the folder with your game and attach it here in a reply (up arrow icon).

Desktop game.zip (542.4 KB)
here you go

I didn’t get to fiddle with the handle_geometry_contact() function as I found out that you are having an issue with the tilemap collision. Rectangular tiles in defold don’t get automatically merged into one collision object, instead each individual tile is an individual collision object, meaning that when you are walking on the ground, you are not walking on a single big rectangle, but on many smaller rectangles.
And your character ever so slightly touches the left and right sides of those individual rectangular collision objects, resulting in strong horizontal normals, that glitch your character animation loop.

There is no single “right” solution how to solve this issue. You can use a different body layout (legs collision sphere at the bottom to detect falling, left and right collision box on the sides to prevent walking through walls), you can add more checks to the code to filter those bad normals.

My personal recommendation is to use Tiled editor to draw your levels and use “object layer” to draw collision boxes on the level. In Tiled you can draw a single collision rectangle over the entire ground so you would not get those wrong normals.
I’ve made a proof of concept Tiled Lua format loader for Defold. However it might be difficult to work with if you are new to Defold.

2 Likes

thank you very much for your help. I had a feeling that it was something to do with the tilemap since i saw the sprite physics arrows going crazy in the debugging mode when travelling over each block.
Since i’m new i don’t fully understand but i’ll investigate the code you’ve given me. Thanks again

1 Like

@GabrielBW a related topic that might help you more Horizontal force applied to game object from tile map collision shape

1 Like