# Box2D Forums

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

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Tweaking Contact Relative VelocityPosted: Sat Aug 14, 2010 1:19 pm

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

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Sun Aug 15, 2010 8:58 pm

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931

Top

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Wed Aug 18, 2010 11:31 am

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

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Tue Nov 22, 2011 12:17 pm

Joined: Mon Sep 05, 2011 11:33 am
Posts: 7
Cause I have boxes, that randomly change directions...

Top

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Tue Nov 22, 2011 8:38 pm

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

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Fri Nov 25, 2011 10:17 am

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

Top

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Sat Nov 26, 2011 12:29 am

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

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Sat Nov 26, 2011 8:29 pm

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

 Post subject: Re: Tweaking Contact Relative VelocityPosted: Wed May 09, 2012 9:41 am

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: