uneven terrain

Hi,

How do I add a physics body with uneven terrain for a motorbike game?

Say I have terrain that a motorbike will go over and it is horizontal but a little rocky/bumpy.

I know you can only add custom convex shapes in Corona (still not sure what that means as convex is ciricular)

The only thing I thought of was having a whole lot of little triangle son a flat surface which sounds messy. [import]uid: 138547 topic_id: 25710 reply_id: 325710[/import]

take a look at this: http://www.youtube.com/watch?v=GYiFuYBg9zY
here’s the code: https://github.com/ansca/TinyPenguin

It’s not exactly what you requested.
But maybe you can be inspired :wink:

-finefin [import]uid: 70635 topic_id: 25710 reply_id: 103952[/import]

I was after rocky terrain ‘more flat type surface’.

To create a custom shape then I need to use a convex shape . I am not sure what they mean by this with Corona.

If I use a program to give me the points in a clockwise direction then is this what I do? It would be more like a series of small triangle shapes for a rocky flat type terrain. [import]uid: 138547 topic_id: 25710 reply_id: 103999[/import]

Hey check this out. I experimented with what you’re talking about a while back, and went and touched up the code with some comments:

http://developer.anscamobile.com/forum/2011/04/09/generating-some-random-terrain-physics-terrain-segments

Might help? Hope so!

-Mario [import]uid: 11636 topic_id: 25710 reply_id: 104019[/import]

@mroberti: looks nice !

@jagguy999: as for “convex vs concave” I think you can’t make hollow physical objects. [import]uid: 70635 topic_id: 25710 reply_id: 104026[/import]

You really should try out PhysicsEditor. It will Auto trace your png file and create your physics in two ticks of a tock.

You wont have to worry about convex shapes either as physics editor will take care of it for you. [import]uid: 99431 topic_id: 25710 reply_id: 104085[/import]

For non-procedural/random generated terrain, hell yeah I agree! PLUS you’d get the advantage of the texture of your PNG being included. Maybe jagguy999 can make a couple of building block chunks, so to speak? Textures and all could be included along with the neat clean physics objects too. Just need to add a bit of logic for stringing together some pieces? Or hell, even LevelBuilder by Ricardo Rauber too? Not sure if jagguy999 had his heart set on randomly generated terrain. :slight_smile: [import]uid: 11636 topic_id: 25710 reply_id: 104089[/import]

thanks for the replies I will look at them.

Is there a definition of the difference between concave/convex shapes mean in corona or is it the same as the mathematical definition of convex polygon where every line segment must lie inside the shape.
PhyscicsEditor isnt a free product I see, and if this constructs many shapes from a sprite then you have put them all together in corona in a group? How does this work for collisions? [import]uid: 138547 topic_id: 25710 reply_id: 104091[/import]

As for your question relating to grouping in physics editor, it isnt really a problem as all the tables are automatically created by physics editor in a separate lua file.

All you need to worry about is placing your tiles and calling something like

physics.addBody(image, physicsData:get("image@2x"))

this will pull the physics data that relates to that image when you auto trace it in Physics Editor.

Even though many shapes may be created, its all held in a table, but only needs to be called once as the above example. “Image@2x” might be a piece of terrain with many bumps, and therefore all collisions will work fine.

For instance you could auto trace many objects in PhysicsEditor, and save it through the software as myphysics.lua

In this file will be data similar to this which represents many shapes for one image:

["image@2x"] = {  
  
  
  
  
 {  
 pe\_fixture\_id = "", density = 2, friction = 0, bounce = 0, isSensor=true,   
 filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },  
 shape = { 14, 193 , 3, 199 , -3, 191 , 14, 185 }  
 }  
 ,  
 {  
 pe\_fixture\_id = "", density = 2, friction = 0, bounce = 0, isSensor=true,   
 filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },  
 shape = { -113, 146 , -85, 168 , -74, 186 , -91, 178 , -105, 169 , -118, 152 }  
 }  
 ,  
 {  
 pe\_fixture\_id = "", density = 2, friction = 0, bounce = 0, isSensor=true,   
 filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },  
 shape = { -41, 185 , -29, 199 , -74, 186 , -85, 168 }  
 }  
 ,  
 {  
 pe\_fixture\_id = "", density = 2, friction = 0, bounce = 0, isSensor=true,   
 filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },  
 shape = { -3, 191 , 3, 199 , -29, 199 , -41, 185 }  
 }  
}  

Even if you need 100 images with physics it will all be in this one file.

I know it isnt free, but it saved me far more time than I care to think about. I cant live without it now. Worth every penny and then some. There is some example code with it to get you going.

Typical usage is

local scaleFactor = 1.0  
local physicsData =(require "shapedefs").physicsData(scaleFactor)  
local shape = display.newImage("objectname.png")  
physics.addBody( shape, physicsData:get("objectname") )  

where shapedefs is your PhysicsEditor lua file [import]uid: 99431 topic_id: 25710 reply_id: 104098[/import]

OK I got it working thankyou. I have a ground with many bumps in it and a char walks over each bump.
My question is how do you stop the object on the ground bumping around? I just want to walk smoothly over every bump and not slid back on a slight hill.

I tried increasing gravity, density without much success. [import]uid: 138547 topic_id: 25710 reply_id: 104125[/import]

did you try adjusting the friction levels for both, as the object should slide less with higher values [import]uid: 99431 topic_id: 25710 reply_id: 104176[/import]

ok this worked.

thanks.

started another thread as I want to simulate a motorbike ride ove rocky terrain. [import]uid: 138547 topic_id: 25710 reply_id: 104212[/import]