WCK - Change joint paramaters after initialisation?

I'm using Mayo's World Construction Kit (I can't stress how excellent it is) and I'm attempting to change the speed of a motor joint after the joint has been initialised. Now, this may not be WCK specific, I doubt it. What I want is to set a motor to speed 0 at creation and then later set the speed to 10. I can't get this to work.

Say I have a joint - j1. If I trace j1.speed1 I see the correct value. If I set j1.speed1 = 10, the value is correctly updated. But, the attached object doesn't move. I'm guessing this is because only the initialised value is used.

Is there a way to change the value after initialisation?

Thanks in advance.
First of all, make sure enableMotor = true and strength = some significant value. Then all you have to do is call SetMotorSpeed(10) on the b2Joint.

I also built something into WCK to automate this, that I admit is not very obvious. On your joint component, set the "speed1" and "speed2" properties to your desired speeds, then also set "speedFlag" to something like "myJointFlagOrWhatever". Then you can do this:

Code:
world.setVar('myJointFlagOrWhatever', true);


The joint will then automatically switch to whatever you set for speed2 (if you pass "false" it'll go to speed1). The idea behind this is that the world keeps track of arbitrary "flags", that, when changed, dispatch events to listening objects. So joints listen for "speedFlag" and change their speeds when it's changed. The cool thing about this is you could have a bunch of joints that all listen to the same flag and all turn on / off based on a specific switch.

I really gotta document this thing. 😕
Thanks once again Mayo.

I couldn't get the SetMotorSpeed to work as I can't quite work out how to access b2Joint (I'm using a DemoJoint on the stage). I'll work that one out on my own though as I don't want to keep bugging you - I'm sure it's just a casting issue.

Your setVar function works a treat though.

Thank you.
I managed to work out the casting issue:

(j1.joint as b2RevoluteJoint).SetMotorSpeed(140);

I'm seeing some interesting behaviour though. If I set speed1 to 10 (or any positive value) in the component panel I see my joint affecting the attached body. If I then set a new motor speed in code I see the new speed applied. However, if I set the speed to 0 in the component panel, I see the body stationary as expected, but then if I set the speed in code I don't see the change. That is until an object collides with the body, at which point it begins spinning at the set rate.

Any ideas? I realise Mayo is probably the only person that can answer WCK questions at the moment and I really appreciate the time you're putting into this. Hopefully I'll be able to answer peoples questions too in a while.
That would be sleeping bodies, paul. See the manual for the whys and wherefores.

I admit I haven't looked at your kit mayo, but I think in general your advice should be "cast to the original box2d object and proceed as normal from there", rather than setting up crazy flag systems and whatever, which seems a system that is designed for a rather more specific purpose than Box2Ds full generality.
Ok, I can tell Boris is getting sick of these WCK posts 😉. Feel free to private message me with any questions.

Yeah... the flag system automatically wakes up bodies.

BTW, I never intended this library to be a replacement for actually learning the ins-and-outs of Box2d. If you're going to do anything fancy you're definitely going to have to read and understand the manual. The reason I developed it is I can't stand constructing levels / worlds in code - I like to lay things out in a visual manner. So it's meant to be a productivity tool, not something to hide the scary guts of Box2d.
Edit: Mayo beat me to the reply 😆

-----------------------------------------------

BorisTheBrave wrote:
That would be sleeping bodies, paul. See the manual for the whys and wherefores.


Thanks Boris...

bodyDef.allowSleep = false;

...solved the issue.

Boris, from your previous few comments (not just this thread but other threads too) I get the feeling you are not happy with WCK existing (forgive me if I'm wrong). I can understand that, but the way I see it, a lot of people give up on Box2D because of the steep learning curve. WCK gives users a foot in the door that is instantly satisfying and keeps motivation high. At the same time, you still have to delve into the manual to get things done and in the long term I'm sure that's a good thing for Box2D.

I migrated from APE to Box2D and I have found Box2D to be much harder to learn, but Box2D is so much more feature rich compared to APE that it's worth putting in the extra effort. EDIT: I just found out that I've been banned from the APE user group simply for making a similar statement on their board. How petty 🙄

You aren't going to see complete games written with WCK, but it sure helps a lot with level generation.

Anything that makes my game-making life easier gets a thumbs up in my book. I'd love to be coding Box2D games in notepad, but at the moment WCK is helping me out tremendously and keeps me wanting to learn more.
Yeah, sorry guys, I have been a bit to harsh about this, while mayobutter has been virtue incarnate. These moderator powers are going to my head, evidently. Please, everyone, continue to post your questions, it's what the forum is here for.

I'm not actually annoyed at WCK, I do appreciate how well it lowers the barrier to entry, and of how appallingly hard Box2DFlashAS3 is from an APE perspective (or otherwise). I'm just worried of two things:
1) mayo will get overwhelmed with requests for help as a prominent person to new entrants, despite the fact most questions are little to do with his contribution. This is no one's fault, and I don't think anyone is trying to avoid doing any research at all. I and others read these boards and also help, but it's harder to do that if they are all piled into one thread.

2)That the principles behind it will be extended too far. Components are a truly great way of defining worlds, which has always been painful to do in Box2D. But I don't personally think there's much that components can offer for once the engine is running. I see now that this kit has a significant framework behind it, so it seems more reasonable now.

BTW, it would be better to use b2Body.WakeUp() than disable sleeping entirely, sleeping is a useful optimization.

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