Prismatic Joint - Changing the angle of axis freedom

Hi,
I'm currently using the following to set up a prismatic joint:

b2PrismaticJointDef jointDef;
jointDef.collideConnected = true;
jointDef.Initialize(Body1, groundBody2, Body1->GetWorldCenter(), worldAxis);
_World->CreateJoint(&jointDef);

where worldAxis is initially equal to 0.0f, 0.0f.

This works fine; I get a sprite (Body1) that moves along one axis.
What I want to do next is allow the user to change the axis at any given time (when they click on a button). So, for example the axis is initially horizontal, the user presses a button and the axis is now vertical. Basically, update the worldAxis value.

Redoing the initialization with the new worldAxis figure does nothing. I've looked at the manual and have tried a few things:

1 - changing jointDef.localAxis1
2 - doing a settransform: Body1Body->SetTransform(Body1Body->GetPosition(), 0.5f);
3 - changing jointDef.referenceAngle

while they all updated their values to the new axis, nothing actually happens with Body1, it always continues along the initialized axis.

So i can set the initial axis but I don't know how to update the axis.

I'm new to Box2D and don't really know what I'm doing in certain areas, such as this. Can someone help me? Thanks in advance....
I would recommend destroying the old joint and replacing it entirely, have you tried that yet.
Great!!! Thanks irresistible force for the suggestion.

I'd briefly looked at destroying the joint, but wasn't doing it correctly. Your suggestion made me look at it properly and I've now got something that's working.

Incase any other beginners are stuck on a similar thing here's the code:

b2PrismaticJoint *_joint;
b2PrismaticJointDef _jointDef;

b2Vec2 worldAxis(0.0f, 0.0f);
_jointDef.collideConnected = true;
_jointDef.Initialize(Body1, groundBody2, Body1->GetWorldCenter(), worldAxis);
_joint = (b2PrismaticJoint*)_world->CreateJoint(&_jointDef);

That creates the initial joint bound to the axis 0.0f, 0.0f.

if (_joint) {
_world->DestroyJoint(joint);
_joint = NULL;
}

That destroys the joint, and then simply create it again with new axis:

b2Vec2 worldAxis(0.5f, 0.5f);
_jointDef.Initialize(Body1, groundBody2, Body1->GetWorldCenter(), worldAxis);
_joint = (b2PrismaticJoint*)_world->CreateJoint(&_jointDef);

Thanks!

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