Hi all! and happy first post to me
I'm just getting into the dark gdk and whilst experimenting, i have come across Sparky's collision detection dll's. Seems like good stuff; I intergrated his sliding demo code into my test world and it seems to be working fine (you control a block that can walk up slopes,stairs etc).
My problem with the code itself is understanding how the SC_GetCollisionNormalY() function works. below is a code extract from the sliding demo for the vertical collision detection (seperate from horizontal):
//first handle gravity - seperated from horizontal movement
//to achieve a more realistic effect
//Method: simple - cast a sphere vertically down, if it hits the level then
// position the object there (sticky collision) then move
// on to horizontal movement
// more complex - if we were to only use the simple method the player would be
// allowed to climb almost vertical slopes. Alternative is to
// get the normalY direction to work out how flat the gorund
// below the player is, 0-slope# is flatter, slope#-1 is steeper.
// if it's flat, use sticky collision, if it's steep slide the
// player down the slope. Changing slope# determines how steep the
// player can climb. NOTE: this also effects stairs.
//Check for collision
collide = SC_SphereSlideGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, radius,0 ); //imp: after jumping "vy" will eventually become negative
if(collide > 0){
float ny = SC_GetCollisionNormalY();
if ( dbAbs(ny) > slope ) // slope is set to 0.5 in the demo
{
//FLAT, stick
oldy = SC_GetStaticCollisionY();
}
else
{
//STEEP, slide
x = x - oldx; z = z - oldz;
oldx = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
oldz = SC_GetCollisionSlideZ();
x = x + oldx; z = z + oldz;
}
//ny#<0 means the player has hit a ceiling rather than a floor
if ( ny > slope )
{
//only on ground if standing on flat ground
ground = 1;
vy = 0;
}
else
{
ground = 0;
//if player has hit a flat ceiling then stop vy# movement
if ( ny < -slope ) vy = gravity;
}
}
else
{
//nothing below player, not on ground, add vertical speed to player
oldy = oldy + vy;
ground = 0;
}
Despite the comments i'm struggling to understand what exactly the get function SC_GetCollisionNormalY() returns IN THE CONTEXT OF THIS DEMO (and the dark gdk api doesn't provide a clear description of this function for me). How does this value, compared against the "slope" variable help determine the flatness of the ground? why is dbAbs() applied to it?
I guess i want to know the exact algorithm here, a rather than taking the authors word for it in the comments and copying the code. Everyone is welcome to shed some light