Rotating platform

Hi,

I would like to create a platform that rotates about a given point. So, if you think of a clock face, i want my platform to be at the end of the big hand as it rotates. The platform itself shouldn't rotate though (i.e. I want to be able to place something on the platform as it rotates).

Code:
      *  <-- rotate point 
        \
         \   
        __\____
       |_______|   <-- platform which always faces up as it rotates


I have this working but doing the rotation manually (i.e. kinematic body and setting the position myself). But i guess the correct solution would be to create a revolution joint with a fixed joint limit, dynamic body and relevant force to do the rotation.

Has anyone done something like this before and care to point me in the right direction? I'm kinda new to all this and not sure if this is even close to a solution.

Thanks.
Yes, you're basically right except you don't need to use joint limits. Something like this would work:

Code:
      // The hook - the platform should revolve around this object
      
      b2BodyDef bd;
      bd.position.Set(10, 15);
      b2Body* hook = world->CreateBody(&bd);
      
      b2PolygonShape shape;
      shape.SetAsBox(0.3, 0.3);
      
      b2FixtureDef fd;
      fd.shape = &shape;
      fd.density = 0.1f;
      hook->CreateFixture(&fd);      
      
      // The platform
      
      bd.type = b2_dynamicBody;
      bd.position.Set(10, 9);
      b2Body* platform = world->CreateBody(&bd);
      
      shape.SetAsBox(4, 0.5);
      platform->CreateFixture(&fd);   
      
      // The revolute joint
      
      b2RevoluteJointDef jd;
      jd.Initialize(hook, platform, b2Vec2(10, 15)); // The last parameter is the center of rotation
      jd.collideConnected = false;
      jd.enableLimit = false;  // No need for limits
      world->CreateJoint(&jd);
Cheers yyy.

I'll give this a go 1st thing tomorrow. Thanks for your time.
Hi,

I seem to have this "kind-of" working now but I have a few issues:

Firstly, my platform is at the end of a pendulum. I apply some force on start up but over time the pendulum loses momentum as you'd expect. Is there a effective way to maintain the "swing" of the pendulum?

Secondly, when I place a dynamic cube on the platform it doesn't follow the rotation. Is there a way to do this? Should I check for a collision then match the force from the pendulum to the object on the platform? (is there such a function as get current force?)

Thanks.
As for the platform, you can use the motor feature: just add jd.EnableMotore(true); and jd.SetMotoreSpeed(3); for example.

As for the cube, I'm not sure what you mean but maybe you should set the friction values of the platform and the cube to the maximum.
Thanks yyy,

The "cube" issue was due to poor friction values my me and is now ok.

The rotate problem is slight more tricky. I didn't use a revolution joint as I couldn't get it to work as required. No matter what i done the platform rotated as the joint rotated. I fixed this my changing to a distance joint and set the platform to fixedRotation=true. This ensured that platform had the same rotation as it was rotated by the joint.

I guess the down side to this is that I cannot use the motor as, as far i know, it's not available for distance joints. Hence i either have to use revolution joint and overcome that issue OR find a way to apply constant rotation to a distance joint.

bailster.

Original thread: https://box2d.org/forum/viewtopic.php?t=6709