Simple Static vs Dynamic collision (Not sure if bug)

General discussion about the R.U.B.E editor
Post Reply
SimAV
Posts: 3
Joined: Mon Mar 25, 2013 12:00 pm

Simple Static vs Dynamic collision (Not sure if bug)

Post by SimAV »

Hey all, I've just started using RUBE in my Flash (AS3) projects but am having trouble even with simple scenarios like a static cube and a dynamic circle.

I export the RUBE scene to JSON and load that into my code but when I run the program the circle does not collide with the square as I would expect (fall due to gravity, connect with the square, bounce a little and eventually come to rest) as this is what happens when I test it in RUBE itself. What actually happens though is the circle slowly clips THROUGH the square til half the circle is submerged within it, then it drops through extremely fast off screen.

I've noticed when setting up the box2D world in Flash the gravity is set to a positive Y figure as 0,0 is in the top left of the screen, however with RUBE 0,0 would be the bottom left. Does the direction of gravity versus the vertices of the static body have any impact?
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Simple Static vs Dynamic collision (Not sure if bug)

Post by iforce2d »

It sounds like the polygon winding might be reversed, you often get that kind of behavior when it is. One quick way to check would be to use just circles only, instead of polygons.
I wonder if you are doing something like reversing the y-coordinates to match the fact that the y-axis goes the other way in Flash? That would reverse the vertex windings...
SimAV
Posts: 3
Joined: Mon Mar 25, 2013 12:00 pm

Re: Simple Static vs Dynamic collision (Not sure if bug)

Post by SimAV »

I think you're right, when I reverse the vector the polygon vertices are stored in it fixes the issue where the ball would fall 'through' the terrain but the collisions still arn't behaving correctly. Rather than roll down the terrain the ball slides (even with high friction) and when it falls off of the edge of the terrain it resumes falling at terminal velocity (no accelerated fall, straight to top speed falling).

Thank you for getting back to me and with the help so far though, I really can't wait to get this fixed so I can start making some good levels =)

EDIT: Just tested without inverting any Y vertices or reversing any order, basically just loading the scene exactly as it is in RUBE (watching it run upside down in flash) and the same 'sliding instead of rolling' behavior happens. I also get the same thing when I use a larger circle instead of the bar, the smaller circle lands on the larger one and 'slides' off of it in the same glitchy manner as before.

EDIT 2: The sliding problem was simply due to the restitution of the fixtures being undefined, a simple check as to whether the JSON file had an element called restitution, and setting to 0 if not worked. Thanks a lot for your help with the polygon winding though, on to loading and creating all the joints now!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Simple Static vs Dynamic collision (Not sure if bug)

Post by iforce2d »

Good to hear you got it sorted.

By the way, are you making your own loader for Flash? I know Emanuele Feronato posted a tutorial where he loaded the basic shapes, I guess maybe you started with that? I know nothing about Flash myself, but I'd like to keep track of what loaders are out there so I can point people to them when they ask me.
SimAV
Posts: 3
Joined: Mon Mar 25, 2013 12:00 pm

Re: Simple Static vs Dynamic collision (Not sure if bug)

Post by SimAV »

Yeah I used the loader Emanuele made as a starting point, didn't work too well when I tried it under similar conditions but it was good to learn the basics of translating the JSON data into AS3 code.

I'm trying to sort the joints out now but am wondering if I've hit a bit of a hitch with the Flash version of Box2D. For revolute joints the JSON file contains data for a bodyA, bodyB, anchorA, anchorB (I presume these are local anchors) and the rest of the data like motorLimit, referenceAngle etc. The code to initialise a revolute joint in AS3 only has 1 parameter for an anchor, do I need to calculate this one anchor in world space from the two local anchors JSON provides?

When I finally manage to get a loader sorted that will load in any body/joint (and I've cleaned it up a little!) I'll let you know and make it available =)
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Simple Static vs Dynamic collision (Not sure if bug)

Post by iforce2d »

I don't really know what they've done with the Flash port, maybe you'll need to look at the source to see which anchor that is for (and probably make a function that takes both anchors :)
Post Reply