# Box2D Forums

 It is currently Fri May 24, 2013 2:16 am

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Simulation problemPosted: Tue Apr 24, 2012 4:30 am

Joined: Tue Apr 24, 2012 4:20 am
Posts: 5
Hello,
I am trying to make tower stability game like 99 bricks at http://apps.facebook.com/silvergames/play/99-bricks.How can i implement automatic tower up/down feature when tower height increase/decrease.Please help me.

Top

 Post subject: Re: Simulation problemPosted: Tue Apr 24, 2012 3:27 pm

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
Keep an array of the bodies, and check their world position. If it is at a certain height threshold in pixels on the screen, offset the camera so the highest body is below the threshold.

Top

 Post subject: Re: Simulation problemPosted: Wed Apr 25, 2012 7:04 am

Joined: Tue Apr 24, 2012 4:20 am
Posts: 5
Heyyy jayther!Thanks for a helpful suggestion.I want that,When tower falls effected bricks falls immediately with gravity.Currently i am using world.Step(1/30,10,10).
I have tried world.Step(1/10,10,10) for same but with this,current bricks or flaying bricks also move down fast.Can we specify a different gravity for flaying bricks body?
http://pigmentworld.com/chapter/Game.html

Top

 Post subject: Re: Simulation problemPosted: Thu Apr 26, 2012 1:27 am

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
Are you using the normal gravity for the controlled blocks? Basing it off the 99 Bricks game, it may be better to use a kinematic body and set its linear velocity (using body.SetLinearVelocity()) so it's not affected by gravity (or any other outside forces), then when it touches the "tower", turn it into a dynamic body. Another way is keep the controlled block a dynamic body and keep setting its linear velocity. I'm not entirely sure which way is better.

Top

 Post subject: Re: Simulation problemPosted: Thu Apr 26, 2012 5:35 am

Joined: Tue Apr 24, 2012 4:20 am
Posts: 5
Thank you so much! Idea of kinematicBody is working. Is there any APIs or libs are available to implement camera concept with box2d?Currently i am re setting the y position of container movie clip of tower(all bricks and including game base bar). It is working when tower height increase but when tower is falls tower bricks container isn't re set immediately as like 99 bricks and it looks like irritating.16 m is my point to active container re setting code.

Top

 Post subject: Re: Simulation problemPosted: Thu Apr 26, 2012 3:46 pm

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
Box2D without debug draw is just a very good number cruncher. It doesn't worry about visual aspects whatsoever. So there's no direct camera thing in Box2D.

What you're doing (setting the y position of the container movieclip) is fine, actually. However, the way your camera moves is a little different than that of 99 Bricks'. Looks like your camera has intervals of 16 meters. So it seems like the camera latches on a multiple of 16 meters. 99 Bricks simply chooses the highest body and sets that as the target height to move the camera to (and tries to place that target height to the screen threshold), so there's no interval.

Top

 Post subject: Re: Simulation problemPosted: Thu May 24, 2012 2:12 am

Joined: Tue Apr 24, 2012 4:20 am
Posts: 5
hi jayther,
I am facing a problem that blocks are looking mashed when touches other blocks or game base area and behave like a rubber box.I would like to blocks behave like a rigid blocks.
code for blocks generation:-
BricksBodyDef = new b2BodyDef() ;
BricksBodyDef.type = b2Body.b2_kinematicBody
BricksBodyDef.allowSleep=true
BricksBodyDef.position.Set(pxStartX * pxToM,pxStartY * pxToM);
BricksBody = world.CreateBody(BricksBodyDef);
var BrickseShape:b2PolygonShape = new b2PolygonShape ;
BrickseShape.SetAsBox((mWidth * pxToM) / 2,(mHeight * pxToM) / 2);
var BricksFixtureDef:b2FixtureDef = new b2FixtureDef ;
BricksFixtureDef.shape = BrickseShape;
BricksFixtureDef.density =10
var startingVelocity:b2Vec2 = new b2Vec2(0,1);
BricksBody.SetLinearVelocity(startingVelocity);
var BricksFixture:b2Fixture = BricksBody.CreateFixture(BricksFixtureDef);
I change the block body type to dynamic when touches each other using SetType(2)
Is there any problem with my code or i need to set some other properties to overcome this problem?Please help me!

Top

 Post subject: Re: Simulation problemPosted: Thu May 24, 2012 9:33 am

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
This is a normal and common thing with heavy stacked dynamic boxes. I can see that your density is set to 10, which is fairly high in Box2D. Set it at a much lower number, like 1.5 or 0.5 even.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 8 posts ]

 All times are UTC - 8 hours [ DST ]

#### Who is online

Users browsing this forum: Bing [Bot] and 0 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: