Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
i'm not sure how it'll end up but you can also directly change fixtures position in every cycle a little. – Ali.S 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. – Faisal 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 – Ali.S 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... – Faisal 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? – ghost 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) 
  toggle = !toggle 


 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.