4
\$\begingroup\$

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?

\$\endgroup\$
8
  • \$\begingroup\$ i'm not sure how it'll end up but you can also directly change fixtures position in every cycle a little. \$\endgroup\$
    – Ali1S232
    Commented Jun 14, 2011 at 9:58
  • \$\begingroup\$ 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. \$\endgroup\$
    – Faisal
    Commented Jun 14, 2011 at 10:29
  • \$\begingroup\$ 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 \$\endgroup\$
    – Ali1S232
    Commented Jun 14, 2011 at 10:33
  • \$\begingroup\$ 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... \$\endgroup\$
    – Faisal
    Commented Jun 14, 2011 at 11:29
  • 3
    \$\begingroup\$ Is the shake effect actually meant to be an influence on the physics simulation or are you looking for a cosmetic effect? \$\endgroup\$
    – ghost
    Commented Jun 14, 2011 at 15:28

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .