# CollisionHandlerFloor bounces

Hi, i’m a python developer and I’m trying to learn to use the panda3d engine.

I decided to start with Roaming Ralph, made him OO, added jumping, made some changes in the camera… and so far so good. Then i decided to play arround with the CollisionHandler, changing it to a CollisionHandlerFloor.

The jumping now it’s much easier, doesn’t need any special code for falling down… but every step ralph’s take into an uneven terrain, he bounces. The intensity and the time it will bouce depends on how much the setMaxVelocity is set… if it’s not set at all, the camera falls and you can only see the ground… if its 1, he bounces a little when he walks up, and he sloooowly falls when he walks back down, then he bouces again… if its 5 he allways stays on the ground bouncing, and higher it is he will bounce more. This is interesting, he stop bouncing at some time… if the velocity is 1, he will stop quickly, if its 50 it will take a lot longer.

I made some changes in the cam to see if it was a camera issue, but no.

Here is part of the code:

def setupCollisions (self):

base.cTrav = CollisionTraverser()
base.floor = CollisionHandlerFloor()
base.floor.setMaxVelocity(5)

#Ground Ray
self.ralphGroundCol = CollisionNode('ralphRay')
self.ralphGroundRay = CollisionRay()
self.ralphGroundRay.setOrigin(0,0,1000)
self.ralphGroundRay.setDirection(0,0,-1)
self.ralphGroundColNp = self.attachNewNode( self.ralphGroundCol)

Any ideas ?

EDIT: A BETTER VIEW

Some observations:

Ralph bounces when he hit the ground. If he jumps on an even terrain, when he hit back the ground he bouces a little and stop. Then he start walking on the plane terrain and no bounce. This bounce seems like a landing thing, like a vibration made when a object hits the ground.

Also, i have noticed that when he walks up a terrain he sometimes automaticly “jumps” from one point to another instead of sliding like in the original example that had a code to make ralph’s Z the same as the collision point.

Those 2 observations can lead me to conclude that when something hits the ground, it will shake/bounce, and that when he walk on uneven terrains makes ralph “jump” from one point to another with a higher z than the hitting point thus making he hits the ground and then bounce.

Still… no idea how to solve it using CollisionHandlerFloor.

Bouncing/floating is expected behavior for pretty much any collision handler that doesn’t, as you suggested the original code did, snap the model to the point of collision.

Basic theory is that when collision/occlusion is detected, the physics system should apply enough force to push the geometries apart. The amount of force (or sometimes just velocity adjustment) usually ends up proportional to the distance of occlusion. On a flat surface, when all you have is down-force vs collision plane, I’d imagine the floor system is tuned to provide just about the right amount of counter-force. When you walk sideways into a slope of any significant grade, however, your character suddenly ends up significantly below floor level, and gets a significant bump- in the vertical direction only, since to simplify calculations, floors are never generally thought of as pushing sideways. Likewise, when going downhill, you’ll be rapidly alternating between clipping the floor very slightly and starting freefall. Clip the floor and you get a slight push upwards and freefall is halted; and since gravity is just an acceleration over time, the first few ticks of freefall thereafter will be much slower than terminal velocity, i.e. “floating”.

Hence, if your terrain is too rough, you’re probably better off using a more advanced collision handler / physics system. If it’s irregular but doesn’t contain anything steep enough to be a “wall,” the cheap hack is to snap the character to the terrain surface when not airborne (which necessitates a bit more logic to release the snap for jumping and walking off ledges).