# shake / Vibrate a body in box2d?

How do you vibrate or cause a shake effect to a body of type static or dynamic or kinematic. I tried applying forces to a dynamic body in the timeStep, which did not work, as well I tried ApplyLinearImpulse many times a sec within the timeStep, which again did not give me the result. So right now Iam experimenting with adding a static circle body as a hinge point to my rectangular body and create a revolute joint between them. May be then applying a force could result in Tension between the 2 bodies? Does anybody know about this? have any ideas please let me know?

• i'm not sure how it'll end up but you can also directly change fixtures position in every cycle a little. Jun 14 '11 at 9:58
• how would I do that? I had tried repositioning body using setTransform to the left and right a few pixels, the timeStep is too fast the changes are not visible. How would I change fixtures position....just tried googlin.....please let me know thanks. Jun 14 '11 at 10:29
• you can't directly change bodies positions, you have to change fixtures position, if you want to. body->getFixture() gives you access to body's first fixture, for the next fixtures call fixture->nextfixture(). and fixtures have setposition function that you can use to change their positions Jun 14 '11 at 10:33
• I just googled to look for setPosition in b2Fixture class, there isn't any, but b2Body class has setPosition function. As well I tried this b2Fixture *f = body->GetFixureList(); f->setPosition()..setPosition did not come up...the IDE itself is not recognizing i.e in my xcode...still very confused... Jun 14 '11 at 11:29
• Is the shake effect actually meant to be an influence on the physics simulation or are you looking for a cosmetic effect? Jun 14 '11 at 15:28

okay I just figured everything out...all I had to do was to set the linearVeolcity using boolean logic. i.e

if(counter <50)
{
if(toggle)
{
body->setLinearVelocity(5.0,0.0)
}
else
{
body->SetLinearVelocity(-5.0,0.0)
}
toggle = !toggle
}

counter++;

if(counter>50)
{
break away from being static body
}


all of the above code has to go in to the timeStep under the loop in which you iterate the b2Bodies of the world.....the logic is simple.