i did some collision testing with my terrain, and that works quite fine, but i have some trouble with collision response.
i have/had two ideas. the first one was, that every time a collision occurs, i just add something to my y-value to lift my camera. regarding collision this works just fine, but the scene is - of course - flickering not just a bit.
the second idea i had, had to do with reflection. the flickering is gone and everything is smooth. BUT imagine this worst case scenario:
i have to polygons. on is lying quite flat, the other is right “behind” this polygon in an angle almost perpendicular to the first polygon. when i have a collision with the first polygon close to the second polygon and with a flat angle to the first polygon, the reflected vector speeds me far behind the second polygon.
anybody had a similar problem? how do i react if i am this far behind the polygon? or how do i prevent even to get in this scenarion.
i have/had two ideas. the first one was, that every time a collision occurs, i just add something to my y-value to lift my camera. regarding collision this works just fine, but the scene is - of course - flickering not just a bit.
[/b]
Depending on what your collision detection/response is used for, you may try this:
Add a small y-delta to all polygons before collision test. Use your algorithm with adding a y-component when a collision occurs. The magnitude of the addition could perhaps be proportional to the speed of movement and the “slope” of the surface that you hit.
Finally, filter the corrected y coordinate so that the change occurs over time rather than instantaneous (thus removes flickering). The filtering will (in most cases) make the movement look more smooth and “proffesional”.
A simple filter is:
yfilt(n) = k*y(n) + (1-k)*yfilt(n-1)
where k = 2*dt/T, dt = frame duration, T = roughly the time it takes for yfilt to reach 80-90% of y (if y does a step from one value to another and then stays constant).
/Marcus
[This message has been edited by marcus256 (edited 09-07-2001).]
One approach I have used to counteract this is to use a collision hull created from blurring the heightfield data, followed by rescaling. Then using a simple interpolation scheme to determine the minimum height at any point. While not suitable for precise collision detection, it worked just fine for a fly through of the terrain.