One collision node collides to another, and CollisionHandlerPusher() pushes it back. But - it pushes it to its previous position. So, the moving collision node bounces forward and back like crazy, instead of slowly sliding along the surface of the second node. How to smooth it?
(Imagine, I have camera parented to the moving node; it goes mad!)
Here is the test code and the egg.
Code:
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
import sys
base.cTrav = CollisionTraverser()
pusher = CollisionHandlerPusher()
class Into():
def __init__(self):
self.collisionBox = loader.loadModel("collisionBox")
self.collisionBox.reparentTo(render)
self.collisionBox.setPos(0, 5, 0)
self.collisionBox.setH(60)
self.collisionBox.setScale(1.5)
self.collisionBox.setCollideMask(BitMask32.bit(1))
class From(DirectObject):
def __init__(self):
self.fromNode = render.attachNewNode("fromNode")
self.fromNode.setPos(0, 0, 0)
self.fromColNode = CollisionNode("fromColNode")
self.fromColNode.addSolid(CollisionSphere(0, 0, 0, 0.5))
self.fromColNP = self.fromNode.attachNewNode(self.fromColNode)
self.fromColNP.show()
self.fromColNode.setCollideMask(BitMask32.bit(1))
base.cTrav.addCollider(self.fromColNP, pusher)
pusher.addCollider(self.fromColNP, self.fromNode)
self.defineMovements()
def defineMovements(self):
self.accept("w", self.forward)
self.accept("w-repeat", self.forward)
self.accept("s", self.backward)
self.accept("s-repeat", self.backward)
self.accept("escape", sys.exit)
def forward(self):
self.fromNode.setPos(self.fromNode, 0, 0.1, 0)
print "Forward"
def backward(self):
self.fromNode.setPos(self.fromNode, 0, -0.1, 0)
print "Backward"
base.cam.setPos(0, 0, 20)
base.cam.lookAt(0, 0, 0)
intoO = Into()
fromO = From()
run()
The egg. Name is “collisionBox.egg”, and put to the same directory:
<CoordinateSystem> { Z-up }
<Comment> { "Egg laid by Chicken for Blender vR44" }
<Group> car-col {
<Collide> { Polyset keep descent }
<Transform> {
<Matrix4> {
1.000000 0.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000
0.000000 -1.000000 0.000000 0.000000
0.000000 0.000000 0.000000 1.000000
}
}
<VertexPool> car-col {
<Vertex> 0 {
2.31999993324 4.78000068665 3.27196502686
}
<Vertex> 1 {
2.31999993324 4.78000020981 3.33753487212e-005
}
<Vertex> 2 {
-2.32000041008 4.78000020981 3.36137673003e-005
}
<Vertex> 3 {
-2.31999993324 4.78000068665 3.27196550369
}
<Vertex> 4 {
2.3200006485 -4.77999973297 3.27196598053
}
<Vertex> 5 {
-2.31999969482 -4.77999973297 3.27196645737
}
<Vertex> 6 {
-2.32000017166 -4.78000020981 3.45739463228e-005
}
<Vertex> 7 {
2.31999921799 -4.78000020981 3.38586905855e-005
}
<Vertex> 8 {
2.31999993324 4.78000068665 3.27196502686
}
<Vertex> 9 {
2.3200006485 -4.77999973297 3.27196598053
}
<Vertex> 10 {
2.31999921799 -4.78000020981 3.38586905855e-005
}
<Vertex> 11 {
2.31999993324 4.78000020981 3.33753487212e-005
}
<Vertex> 12 {
2.31999993324 4.78000020981 3.33753487212e-005
}
<Vertex> 13 {
2.31999921799 -4.78000020981 3.38586905855e-005
}
<Vertex> 14 {
-2.32000017166 -4.78000020981 3.45739463228e-005
}
<Vertex> 15 {
-2.32000041008 4.78000020981 3.36137673003e-005
}
<Vertex> 16 {
-2.32000041008 4.78000020981 3.36137673003e-005
}
<Vertex> 17 {
-2.32000017166 -4.78000020981 3.45739463228e-005
}
<Vertex> 18 {
-2.31999969482 -4.77999973297 3.27196645737
}
<Vertex> 19 {
-2.31999993324 4.78000068665 3.27196550369
}
<Vertex> 20 {
2.3200006485 -4.77999973297 3.27196598053
}
<Vertex> 21 {
2.31999993324 4.78000068665 3.27196502686
}
<Vertex> 22 {
-2.31999993324 4.78000068665 3.27196550369
}
<Vertex> 23 {
-2.31999969482 -4.77999973297 3.27196645737
}
}
<Polygon> {
<Normal> { -0.000000 1.000000 -0.000000 }
<VertexRef> { 0 1 2 3 <Ref> { car-col } }
}
<Polygon> {
<Normal> { 0.000000 -1.000000 0.000000 }
<VertexRef> { 4 5 6 7 <Ref> { car-col } }
}
<Polygon> {
<Normal> { 1.000000 -0.000000 -0.000000 }
<VertexRef> { 8 9 10 11 <Ref> { car-col } }
}
<Polygon> {
<Normal> { -0.000000 -0.000000 -1.000000 }
<VertexRef> { 12 13 14 15 <Ref> { car-col } }
}
<Polygon> {
<Normal> { -1.000000 -0.000000 0.000000 }
<VertexRef> { 16 17 18 19 <Ref> { car-col } }
}
<Polygon> {
<Normal> { 0.000000 0.000000 1.000000 }
<VertexRef> { 20 21 22 23 <Ref> { car-col } }
}
}