hey i got a small (big) problem, the fact is, that i got this sliding collision thing working on my map, but there is a major flaw in the programming (either by me or the demo).
i have reviewed my code and ensured myself that the problem lies in the movement and checking collision function (which will be posted at the bottom of this post).
The dilemma is that the scale of the world is more vast than the demo, and therefore i am having problems getting my character to move at a more realistic speed, and still having working collisions (the problem with this is glitching through objects).
So what i have done is i made the movement in the demo *4 more effective, this also modified the collision calculations (which to me makes it seem that it will work).
My other option is to rescale the whole world relatively to the demo (which imo will be unneeded and a lot of work).
My code is a copy of the tutorial and follows:
// this function is ran every loop
void sparcol()
{
float oldx = dbObjectPositionX(3);
float oldy = dbObjectPositionY(3);
float oldz = dbObjectPositionZ(3);
//apply gravity, and user changes to movement
float angy = dbObjectAngleY(3);
vx = 0;
vz = 0;
dbText (0,365,dbStr(angy));
vy = vy + gravity;
if (dbKeyState(32) == 1 ) { vx = vx + dbCos(angy); vz = vz - dbSin(angy); }
if (dbKeyState(30) == 1 ) { vx = vx - dbCos(angy); vz = vz + dbSin(angy); }
if (dbKeyState(31) == 1 ) { vx = vx - dbSin(angy); vz = vz - dbCos(angy); }
if (dbKeyState(17) == 1 ) { vx = vx + dbSin(angy); vz = vz + dbCos(angy); }
float x = oldx + (vx*4);
float y = oldy + vy;
float z = oldz + (vz*4);
dbText (0,380,dbStr(x));
dbText (0,395,dbStr(z));
int collide = SC_SphereCastGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, radius,0 );
if ( collide > 0 )
{
//how flat is this ground
float ny = SC_GetCollisionNormalY();
if ( dbAbs(ny) > slope )
{
//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;
}
dbPositionObject( 3,x,oldy,z );
SC_UpdateObject( 3 );
dbText (0,150,dbStr(vy));
}
Object 3 is the player, and all the objects that it is checking for collision stay STATIC.
To outline the problem, when you go up to a wall, it will repel you, but if you keep walking eventually (after about 2 seconds) it will kick you through the wall, and i conclude this is because of the amount it repels you.
TYVM in advance
(object used is attached, it is downloadable from a thread on this site)