Box2D Forums

It is currently Tue May 21, 2013 5:20 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Aug 14, 2010 1:19 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
I'm hacking the contact solver to change "relative velocity at contact" to provide conveyor belt functionality, and need help figuring out why a few objects wont go in the right direction of the conveyor belt / suddenly change direction for no reason. Here's a demo (if it's not the "conveyor belt" demo then cache is preventing reloading):

http://www.sideroller.com/wck/?f=11

Every once in a while one of the triangles will go in the wrong direction.

And here's the hack:

Code:
// Relative velocity at contact
b2Vec2 dv = vB + b2Cross(wB, ccp->rB) - vA - b2Cross(wA, ccp->rA);

int flip = (c->manifold->type == b2Manifold::e_faceB ? -1 : 1);
dv.x += c->fixtureA->m_conveyorBeltSpeed * tangent.x * flip;
dv.y += c->fixtureA->m_conveyorBeltSpeed * tangent.y * flip;
dv.x -= c->fixtureB->m_conveyorBeltSpeed * tangent.x * flip;
dv.y -= c->fixtureB->m_conveyorBeltSpeed * tangent.y * flip;


Is there something else I should take into account to flip the effect? I figured taking into account the manifold type (faceA, faceB) would be allI needed.


Top
 Profile  
 
PostPosted: Sun Aug 15, 2010 8:58 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
You should add a bias to vt instead.


Top
 Profile  
 
PostPosted: Wed Aug 18, 2010 11:31 am 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
Ok, below is what I ended up with. I still get triangles that randomly change direction though. Obviously under certain circumstances I need to flip the direction of "vt" but I cannot fathom what that condition could be. And why only the triangles?!?

Code:
// Compute tangent force
float32 vt = b2Dot(dv, tangent);
         
int flip = (c->manifold->type == b2Manifold::e_faceB ? -1 : 1);
vt += c->fixtureA->m_conveyorBeltSpeed * flip;
vt -= c->fixtureB->m_conveyorBeltSpeed * flip;


Anyway thanks, close enough I guess.


Top
 Profile  
 
PostPosted: Tue Nov 22, 2011 12:17 pm 
Offline

Joined: Mon Sep 05, 2011 11:33 am
Posts: 7
I just wonder, was this issue solved?
Cause I have boxes, that randomly change directions...


Top
 Profile  
 
PostPosted: Tue Nov 22, 2011 8:38 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
The SVN version has built in support for conveyor belts and there is an example in the testbed.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 10:17 am 
Offline

Joined: Mon Sep 05, 2011 11:33 am
Posts: 7
I'm using this conveyor belt and objects are moving randomly.


Top
 Profile  
 
PostPosted: Sat Nov 26, 2011 12:29 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Did you use the same logic as this code from ConveyorBelt.h?

Code:
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
   Test::PreSolve(contact, oldManifold);

   b2Fixture* fixtureA = contact->GetFixtureA();
   b2Fixture* fixtureB = contact->GetFixtureB();

   if (fixtureA == m_platform)
   {
      contact->SetTangentSpeed(5.0f);
   }

   if (fixtureB == m_platform)
   {
      contact->SetTangentSpeed(-5.0f);
   }
}


Top
 Profile  
 
PostPosted: Sat Nov 26, 2011 8:29 pm 
Offline

Joined: Mon Sep 05, 2011 11:33 am
Posts: 7
Looks like we are talking about different things. :)
I'm using WCK with Box2D Flash Alchemy Port, so objects are moving randomly over there.


Top
 Profile  
 
PostPosted: Wed May 09, 2012 9:41 am 
Offline

Joined: Thu Nov 04, 2010 9:22 am
Posts: 13
I think I got the reversing direction issue fixed, by getting rid of flip altogether:

Code:
   vt += c->fixtureA->m_conveyorBeltSpeed;
   vt += c->fixtureB->m_conveyorBeltSpeed;


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group