Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Box2d incompatibility for small polygon shaped fixtures (between old and new Gideros) - Gideros Forum

Box2d incompatibility for small polygon shaped fixtures (between old and new Gideros)

kussakovkussakov Member
edited October 2015 in Bugs and issues
Hi,

We could not post our app to the windows store, because we found last minute incompatibility, which made our app partially unusable and in need of fixing.
The incompatibility is not related to Windows, but to box2d in Old(e.g. 2015.03) vs. New Gideros (e.g. 2015.08/09).

The problem: Small fixtures defined as polygon shape turn into a huge square fixtures in the new Gideros, but work fine in the older Gideros.
See the attached image to visualize the problem.

How to reproduce. Just paste this code in a main.lua and run on old and new Gideros.
require "box2d"
 
--b2.setScale(30) -- 30 is default
 
local world = b2.World.new(0, 0)
 
local shape = b2.PolygonShape.new()
 
shape:set(0,1.4, 0,0, 20,0, 20,1.4 )
 
--shape:set(-10,0.7, -10,-0.7, 10,-0.7, 10,0.7 ) -- same(center is irrelevant does not work)
 
--shape:setAsBox(10,0.7) -- Works as box!
 
local bodyDef = {type = b2.DYNAMIC_BODY, position = {x = 160, y = 210}}
local body = world:createBody(bodyDef)
body:createFixture({shape = shape, density = 0.8, friction = 0.2})
 
local debugDraw = b2.DebugDraw.new()
world:setDebugDraw(debugDraw)
stage:addChild(debugDraw)
This code is also attached.

If you play in 2015.03 - it works.
If you reduce the b2 scale (from say 30 to 20) it starts working in 2015.08/09.
If you use setAsBox to create the same fixture - also works in 2015.08/09.

Any ideas?
Any advice for a workaround other than "make bigger fixtures"?:)

Thanks

Vlad
cigerosBox2dIncomp.png
800 x 800 - 9K
lua
lua
main.lua
593B

Comments

  • I bumped into this problem last week, check out the post below. I wasn't aware this is an issue with the latest Gideros.

    http://giderosmobile.com/forum/discussion/6040/box2d-and-gideros-and-the-ever-mystifying-units#Item_8
    My Gideros games: www.totebo.com
  • kussakovkussakov Member
    edited October 2015
    Something changed in the last 6 months. Not sure when...
    For 2 years we are posting apps on Andorid and iOS stores using older Gideros.
    Now we are using the new one, so that we can post to the Windows store.
    And the games are not working well because of that incompatibility.

    And please note: You can make much smaller fixtures using "setAsBox" shape.
    It does not work when it is a polygon shape.
    If I reduce the b2 scale for 30 to 20 - this will mess up velocities and other things.
  • Guys any ideas?
  • recently box2d was upgrade to liquid fun, it is possible liquid fun has those bugs in their box2d version.
  • hgy29hgy29 Maintainer
    @kussakov, I just digged into box2d internals, and I found out that some specific checks are made on polygon vertices you give. One of those check tries to simplify your polygon by removing vertices which have a squared distance below 0.0025, thus a distance below 0.05 in box2d units.

    If you use a physics scale of 30, then the minimum distance become 1.5 in gideros units. For a scale of 20, the distance would be 1.0.
    In your example you have two vertices 1.4 units apart, which will be collapsed at scale 30 and kept at scale 20. This is the same issue as @totebo.

    However I am too new to gideros to figure out when this change was made or what caused it. A possible fix would be to lower the minimum distance in box2d (b2LinearSlop in b2Settings.h). Does this ring a bell to someone else ?
  • Nicely found. Can it be changed to a more granular setting?
    My Gideros games: www.totebo.com
  • Interesting!
    And very weird.
    I just checked the source codes history of bwSettings.h
    b2_linearSlop is 0.005f in the new version and in the older versions.
    Looks like liquidfun-1.0.0 is used even in 1 year old versions of Gideros.
    Checked the web too for older versions of Box2d and liquidfun. Looks like it has always been 0.005f.
    The polygon radius parameter - same thing.

    @hgy29 - thank you for researching this!
    I don't think we should change this parameter - it looks like it affects collisions, etc. and it has been the same for some time

    I guess it is a bug of some sort. If the polygon has 4 vertices and you remove 2 - it becomes a line. It should not do that :-)

    I guess I will change the game.
    My issue is that the characters are scaled depending on the situation and *sometimes* some little fixture goes below 1.5 points.
    More extra work :-(

Sign In or Register to comment.