Hi guys,
I’m trying to create an endless side scrolling game.
I’m generating a random heightmap, smooth it and build an polygon from it and of course, I’m adding an body.
One hill element is not fixed in its’ height; sometimes there are more hills than on others hill elements. But that causes the problem that the physics body is not aligned to the polygon.
To align two hill elements together, the last heightmap value gets saved and applied to the spawn location y-direction. That works, but since the polygon has varying heights, it’s not aligned properly too.
And some of my code where I am creating the hills:
function createHill()
--top margin
hill_margin_top = hill_margin_top + getLastHillHeight()
-- vertices
local vertices = generateHillVertices()
-- spawn location
local x = spawnY + getHillWidth()/2 + hill_margin_left
local y = spawnY + HILL_DEPTH/2 + hill_margin_top
-- hill creation
local new_hill = display.newPolygon(world, x, y, vertices)
-- body
physics.addBody( new_hill, "static", { outline=vertices, bounce=0.1, friction=1 } )
--left margin
hill_margin_left = hill_margin_left + getHillWidth()
end
So, how do I bring the polygon and its body together? I couldn’t find a way to move the body in reference to the polygon.
Thank you in advance!