Make a scrolling platform [solved]

Hi everybody !

I decided to create another topic because the last was not appropriated.

I want to make a scrolling platform with box2D but I can't get it.
I'm trying with two bodies, one static and sensor and one normal which would be the platform.
And then I link them with a PrismaticJoint, with a motor and an axe parallel to the ground to make it scroll…

But, the fact is that, it doesn't work and moreover, my body just fall down as he shouldn't… It doesn't do anything but that…
So what can I do ? Could you help me please ?

Thanks a lot in advance ! 😀

edit : I finally made it scroll with an evoluting setSpeed each frame, but it still goes down… And I didn't find how to get the right length for the movement. I tried changing every parameter of the joint but it seems it doesn't change anything.
Up ! I really need your help please…
Please try to write some code that will run in the testbed and show your problem. Please post the code here.
Here it is : http://paste-it.net/public/ed4e114/ (sorry for the time I past on)
But there is apparently a problem with it, because when I tried to launch it in testbed, I got a 'segmentation default'…
Well, I hope it'll work with you because I think I didn't really got how does prismatic joints work.

Thanks 😀
You need to create the joint between ground and your body.

Try changing this line:
Code:
jointDef.Initialize(m_body, m_hollow, m_body->GetWorldCenter(), worldAxis);


To this:
Code:
jointDef.Initialize(ground, m_body, m_body->GetWorldCenter(), worldAxis);


Also get rid of this line (it is redundant and causes problems with the prismatic joint):
Code:
bodyDef.fixedRotation = true;


I'm guessing your sensor should just be another fixture on m_body. So get rid of m_hollow.

Also, you should try debugging that segmentation fault. Run the code in debug mode through a debugger and find out which line causes the crash.
Well, I tried what you told me (but the debug -- with what could I debug it ?)., but…
Now, my plateform goes down as before but it goes under the ground (and I checked, the ground does not move).

Thanks
It sounds like you need to go learn C++ programming a bit better. I don't recommend trying to develop with Box2D until you learn how to run a debugger. For example, you can download Visual Studio Express for free and debug in that. There are many other tools out there.
Yes… But in fact I'm working on Mac OS X and… well…
I work with the terminal and so I don't work with any debugger x)
I'm actually trying with Xcode but I need to find out how to use the makefile…

edit : I put some cout in the code I wrote to check… But all of them are written in the terminal before the segmentation fault…
Sheeft wrote:
Yes… But in fact I'm working on Mac OS X and… well…
I work with the terminal and so I don't work with any debugger x)
I'm actually trying with Xcode but I need to find out how to use the makefile…

edit : I put some cout in the code I wrote to check… But all of them are written in the terminal before the segmentation fault…

Unfortunately, C++ being what it is, developing in C++ without a debugger isn't very practical. Also, when you post to a forum such as this one, most people will expect you to have already tried to solve the problem yourself using the debugger before posting.

Regarding the OS X issue, you could try using Xcode, which incorporates GDB. I think you can also use GBD from the terminal, although I've never tried this myself.

Personally, I haven't found GDB to be very easy to work with, but that may just be because I haven't had a chance to use it on a newer Mac with plenty of memory, etc. In any case, I'd recommend looking into GDB, and if running it from the command line doesn't seem appealing, you might look into moving your development into the Xcode environment.

Again though, to do any sort of serious development in C++ you really have to have a debugger available, so now is probably as good a time as any to dive in :)
Oh great ! Thanks it helps me a lot.
I use GDB with the terminal and I got that :
Quote:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x0000000100024690 in b2PrismaticJoint::GetMotorForce ()


So it means I've done something bad with my b2Prismatic pointer right ?
I'll take a look at that 🙂

EDIT : Okay, I found what was my error.
Now this should work : http://pastie.org/1050213 😉

But as you can see, the body falls…

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