behdad / box2d

Automatically exported from code.google.com/p/box2d
2 stars 12 forks source link

Conveyor belt effect via PreSolve #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://www.box2d.org/forum/viewtopic.php?f=3&t=2861

The above thread from a couple of years ago discusses a method for getting a 
conveyor belt effect, by adjusting the relative velocity between surfaces in 
the contact solver. Erin mentions where something like that would fit into the 
API, and then he makes the perfect thing a few months later: PreSolve. How 
about something like b2Contact::ModifySurfaceVelocity(float32) which alters the 
tangential part of the contact impulse, but only for a single time step in the 
same way that SetEnabled works.

Trying this recently I was pleased to see what a great effect I got for such a 
small amount of coding. It allows tank tracks to be computationally cheap and 
pretty much indestructible, instead of the fully simulated type which are 
time-consuming to set up, stretchy and fragile. Nice one mayobutter!

Original issue reported on code.google.com by iforc...@gmail.com on 5 Jul 2011 at 6:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
It seems like that function would have a specific and limited application. Why 
not just schedule this in PreSolve for after the physics time step and use 
something like contact->GetFixtureA()->GetBody()->SetLinearVelocity() with 
direction based on the tangent of oldManifold->localNormal and the speed based 
on how fast you want the conveyor to be?

Original comment by rocif...@gmail.com on 29 Aug 2011 at 3:48

GoogleCodeExporter commented 9 years ago
Yeah, it does seem quite specific and I don't see many people clamoring to have 
it implemented, which I guess is why it hasn't been added. I have it on my 
todo-list to make a demo with source code showing how I approached this, it 
will be interesting to see how much attention it gets. That's probably a few 
more weeks away, in the meantime you can see how it looks in practice: 
http://www.youtube.com/watch?v=yGU1E6wQFqE

I believe the SetLinearVelocity() method only works when used on static bodies, 
so it doesn't handle dynamic/dynamic contacts. Other issues are that it would 
affect all other bodies touching the static body as opposed to having each pair 
of bodies controllable individually, and you'd need to keep track of when to 
set the velocity back to normal somehow.

Original comment by iforc...@gmail.com on 30 Aug 2011 at 8:21

GoogleCodeExporter commented 9 years ago
Ah cool video, I actually found this the other day, and was impressed. I am 
looking at creating some kind of water elevator for our game. Here's a video of 
the water simulation I've implemented http://www.youtube.com/watch?v=NxosUZCF-bE

Do you think some kind of fully simulated tracks for an escalator would work, 
or would you use the method you've done and fake any motion by rendering 
animated sprites? The box2d json project had a great looking tank that had 
fully simulated tracks, but I think your solution is more elogant and robust 
for a game environment.

Original comment by rocif...@gmail.com on 30 Aug 2011 at 8:36

GoogleCodeExporter commented 9 years ago
It looks like you will need fully simulated buckets or something to carry those 
particles. The only way they would be make it up a fake-surface-velocity slope 
is if they were square enough not to roll down :)

Original comment by chriszca...@gmail.com on 30 Aug 2011 at 10:10

GoogleCodeExporter commented 9 years ago
http://www.iforce2d.net/b2dtut/conveyor-belts

Original comment by iforc...@gmail.com on 27 Oct 2011 at 8:20

GoogleCodeExporter commented 9 years ago
Command: Commit  
Modified: D:\Development\Box2D\Box2D\Box2D\Collision\b2BroadPhase.cpp  
Modified: D:\Development\Box2D\Box2D\Box2D\Common\b2Settings.cpp  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2Contact.cpp  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2Contact.h  
Modified: 
D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2ContactSolver.cpp  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2ContactSolver.h  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PulleyJoint.cpp  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PulleyJoint.h  
Modified: D:\Development\Box2D\Box2D\Build\vs2010\Testbed.vcxproj  
Modified: D:\Development\Box2D\Box2D\Build\vs2010\Testbed.vcxproj.filters  
Modified: D:\Development\Box2D\Box2D\CMakeLists.txt  
Modified: D:\Development\Box2D\Box2D\Documentation\manual.docx  
Adding: D:\Development\Box2D\Box2D\Testbed\Tests\ConveyorBelt.h  
Modified: D:\Development\Box2D\Box2D\Testbed\Tests\Gears.h  
Modified: D:\Development\Box2D\Box2D\Testbed\Tests\Pulleys.h  
Modified: D:\Development\Box2D\Box2D\Testbed\Tests\TestEntries.cpp  
Sending content: D:\Development\Box2D\Box2D\Testbed\Tests\Pulleys.h  
Sending content: D:\Development\Box2D\Box2D\Documentation\manual.docx  
Sending content: D:\Development\Box2D\Box2D\Testbed\Tests\Gears.h  
Sending content: 
D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PulleyJoint.h  
Sending content: 
D:\Development\Box2D\Box2D\Build\vs2010\Testbed.vcxproj.filters  
Sending content: D:\Development\Box2D\Box2D\Testbed\Tests\TestEntries.cpp  
Sending content: D:\Development\Box2D\Box2D\Box2D\Collision\b2BroadPhase.cpp  
Sending content: D:\Development\Box2D\Box2D\Testbed\Tests\ConveyorBelt.h  
Sending content: 
D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2ContactSolver.cpp  
Sending content: 
D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2ContactSolver.h  
Sending content: 
D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2Contact.cpp  
Sending content: D:\Development\Box2D\Box2D\Box2D\Dynamics\Contacts\b2Contact.h 

Sending content: D:\Development\Box2D\Box2D\Box2D\Common\b2Settings.cpp  
Sending content: D:\Development\Box2D\Box2D\CMakeLists.txt  
Sending content: D:\Development\Box2D\Box2D\Build\vs2010\Testbed.vcxproj  
Sending content: 
D:\Development\Box2D\Box2D\Box2D\Dynamics\Joints\b2PulleyJoint.cpp  
Completed: At revision: 238  

Original comment by erinca...@gmail.com on 14 Nov 2011 at 5:46