Collision glitches

Hello!

I’ve made an object that moves at constant speed (by setting linear velocity each frame) and have two sensors - one detecting if the object is touching the ground and one for detection of collision with walls. Then I’ve made a level where some squares are in line (they all have the same Y coordinate). The problem is that the object SOMETIMES stops as seen in the screenshot. Is it something I made wrong? Is there any way to prevent that?

This is how I add the dynamic object:

physics.addBody(player, "dynamic",         { density = 1.0, friction = 0, bounce = 0},         { shape = {20, 0, 20, 40, -20, 40, -20, 0}, isSensor=true },         { shape = {35, -20, 35, 20, 0, 20, 0, -20}, isSensor=true }     ) player.isFixedRotation = true

This is how I add level tiles:

local bodyMaterial = { density = 1.0, friction = 0, bounce = 0 } local obj = display.newRect(x \* 64, y \* 64, 64, 64) physics.addBody(obj, "static", bodyMaterial) camera:add(obj, 1) -- Im using Perspective lib, player object is in the same layer.

Button touch event (began):

player:applyLinearImpulse(0, -120, player.x, player.y)

Thanks in advance.

Can you try it without using the perspective library?

Rob

>> The problem is that the object SOMETIMES stops

i assume by “stops” you’re talking about the x-velocity, right?

(y-velocity should “stop” because you’ve specified zero bounce)

does your player normally “slide” along the tops of these aligned tiles when not jumping?  and then, SOMETIMES, when its leading edge reaches the edge of the next tile, it collides and stops.  if so, then you’ve got the classic “stuck” problem of box2d wrt tiled maps vs fixed rotation dynamic body.  google it - the cause is well known (horizontal collision normals).

“ghost vertices” are the proper way to solve it with box2d, but no support for that yet in corona.

some possible fixes (with varying success and/or side-effects) include:

  model your player instead with a circle (circles won’t get stuck like rect corner)

  model your player instead with a polygon, with tiny chamfer across the bottom corner of rect (allows “deflect” out of stuck)

  merge adjacent horizontal tiles into a single larger horizontal rect (so no vertical seams remain to get stuck on)

  model the continuous upper edge outline of your tiles as an connected edge shape instead of individual rects

  model each tiles as a polygon, with a similar chamfer across top corners (as described above for player)

Correct.

Changing my player object to a polygon made it get stuck even more often. When I used a circle it started to do tiny bumps. Merging is something I have to consider, especially because it’s not that hard.

Making tiles as polygons works and it’s the solution I’m going to use for now.

Thank you both for your time  :wink:

Can you try it without using the perspective library?

Rob

>> The problem is that the object SOMETIMES stops

i assume by “stops” you’re talking about the x-velocity, right?

(y-velocity should “stop” because you’ve specified zero bounce)

does your player normally “slide” along the tops of these aligned tiles when not jumping?  and then, SOMETIMES, when its leading edge reaches the edge of the next tile, it collides and stops.  if so, then you’ve got the classic “stuck” problem of box2d wrt tiled maps vs fixed rotation dynamic body.  google it - the cause is well known (horizontal collision normals).

“ghost vertices” are the proper way to solve it with box2d, but no support for that yet in corona.

some possible fixes (with varying success and/or side-effects) include:

  model your player instead with a circle (circles won’t get stuck like rect corner)

  model your player instead with a polygon, with tiny chamfer across the bottom corner of rect (allows “deflect” out of stuck)

  merge adjacent horizontal tiles into a single larger horizontal rect (so no vertical seams remain to get stuck on)

  model the continuous upper edge outline of your tiles as an connected edge shape instead of individual rects

  model each tiles as a polygon, with a similar chamfer across top corners (as described above for player)

Correct.

Changing my player object to a polygon made it get stuck even more often. When I used a circle it started to do tiny bumps. Merging is something I have to consider, especially because it’s not that hard.

Making tiles as polygons works and it’s the solution I’m going to use for now.

Thank you both for your time  :wink: