Box2D Forums

It is currently Thu May 23, 2013 12:02 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue May 22, 2012 2:45 am 
Offline

Joined: Tue May 22, 2012 2:37 am
Posts: 31
Howdy.
Im a new box2d user. And also a relatively new user of as3 (so far i just finished a game with a lot of complicated code like newbs).
But i have a question though.
Knowing that i use box2d 2.02:
How do i add friction to a circle shape since i understood for what i read that circle isnt affected by friction? so far my code for circle body and shape looks like this:

Code:

                        var ballSprite:Sprite=new Ball();
         parent.addChild(ballSprite);
         
         var ballShapeDef:b2CircleDef=new b2CircleDef();
         ballShapeDef.radius=45/(2 * Vals.RATIO);
         ballShapeDef.density=1.0;
         ballShapeDef.friction=0.9;
         ballShapeDef.restitution=0.3;
         
         var ballBodyDef:b2BodyDef=new b2BodyDef();
         ballBodyDef.position.Set(location.x/Vals.RATIO, location.y/Vals.RATIO);
         
         var ballBody:b2Body;
         ballBody=Vals.world.CreateBody(ballBodyDef);
         ballBody.CreateShape(ballShapeDef);
         ballBody.SetMassFromShapes();
         ballBody.m_angularDamping=0.01;
         
         var velocityVector:b2Vec2=new b2Vec2(initVel.x/Vals.RATIO, initVel.y/Vals.RATIO);
         ballBody.SetLinearVelocity(velocityVector);
         
         super(ballBody, ballSprite);



I mean my ball falls to the ground but it just goes on and rotate till it hits another body and then because of angular damping it ll slow a bit but still if it has the slightest movement going, it will continue to move.


Thanks for having the patience to read such insolent question. :D


Top
 Profile  
 
PostPosted: Tue May 22, 2012 3:04 am 
Offline

Joined: Tue May 22, 2012 2:37 am
Posts: 31
hmm i think i found the answer. I actually gota go and make it a polygon with around 14-16 vertices. Hmm and to find out the vertices location on X and Y axis i gota put the pen on the paper... :(


Top
 Profile  
 
PostPosted: Tue May 22, 2012 3:18 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
I think you are talking about rolling resistance rather than friction. Since rigid bodies are perfectly rigid they don't have any natural rolling resistance, so they will roll even on a tiny slope. You would need to use angular damping, but that value seems very low - did you try higher values?


Top
 Profile  
 
PostPosted: Thu May 24, 2012 9:09 am 
Offline

Joined: Tue May 22, 2012 2:37 am
Posts: 31
sorry for my late reply good sir but i was studying box2d these days.
Tried before to increase the angular damping but with no effect the ball would only have stoped after hiting another object IF its speed was already low, so i created a polygondef with 36 vertices that copies an almost perfect circle.
It probably stops from angular damping though and not friction, not sure.


Top
 Profile  
 
PostPosted: Thu May 24, 2012 9:17 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
I see. Making the ball with many sides will work but it's not very efficient if you have many balls like that.
You could mimic rolling resistance by applying a small linear force in the opposite direction to the current velocity of the ball.


Top
 Profile  
 
PostPosted: Thu May 24, 2012 9:30 am 
Offline

Joined: Tue May 22, 2012 2:37 am
Posts: 31
I am yet to find out how to apply force or an impulse to a body.
Could you post an exemple?


Top
 Profile  
 
PostPosted: Thu Aug 16, 2012 4:44 am 
Offline

Joined: Thu Aug 16, 2012 4:34 am
Posts: 1
It's been a while but fwiw: Friction works on circles, it's just that it won't take effect since a circle will choose to roll rather than slide. If it's not important to you that the circle rolls, you can call body.setFixedRotation(true) to stop it from rolling and it will start sliding.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 4 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group