Add Steep Terrain Collision Detection TGEA 1.8.1
by Ian Curtis · 08/17/2009 (3:56 am) · 5 comments
I needed a simple method of calling a function from script when the player was on a steep terrain slope.
Steep being defined by the playerdata datablock variables: runSurfaceAngle and jumpSurfaceAngle.
This will work best for missions with flat terrains where you slope the edges of the terrain to form cliffs/walls, because it will trigger for even small steep bumps and irregularities in the terrain which fall above the threshold set by the above variables.
In player.cpp look for:
// shake camera on ground impact
if( bd > mDataBlock->groundImpactMinSpeed && isControlObject() )
{
F32 ampScale = (bd - mDataBlock->groundImpactMinSpeed) / mDataBlock->minImpactSpeed;
CameraShake *groundImpactShake = new CameraShake;
groundImpactShake->setDuration( mDataBlock->groundImpactShakeDuration );
groundImpactShake->setFrequency( mDataBlock->groundImpactShakeFreq );
VectorF shakeAmp = mDataBlock->groundImpactShakeAmp * ampScale;
groundImpactShake->setAmplitude( shakeAmp );
groundImpactShake->setFalloff( mDataBlock->groundImpactShakeFalloff );
groundImpactShake->init();
gCamFXMgr.addFX( groundImpactShake );
}
immediately after this add:
Recompile the source.
Setup your two variables, and add your new function in player.cs
This should all be working ok, but I've not yet extensively tested it, so feel free to add to it if necessary.
Ian.
Steep being defined by the playerdata datablock variables: runSurfaceAngle and jumpSurfaceAngle.
This will work best for missions with flat terrains where you slope the edges of the terrain to form cliffs/walls, because it will trigger for even small steep bumps and irregularities in the terrain which fall above the threshold set by the above variables.
In player.cpp look for:
// shake camera on ground impact
if( bd > mDataBlock->groundImpactMinSpeed && isControlObject() )
{
F32 ampScale = (bd - mDataBlock->groundImpactMinSpeed) / mDataBlock->minImpactSpeed;
CameraShake *groundImpactShake = new CameraShake;
groundImpactShake->setDuration( mDataBlock->groundImpactShakeDuration );
groundImpactShake->setFrequency( mDataBlock->groundImpactShakeFreq );
VectorF shakeAmp = mDataBlock->groundImpactShakeAmp * ampScale;
groundImpactShake->setAmplitude( shakeAmp );
groundImpactShake->setFalloff( mDataBlock->groundImpactShakeFalloff );
groundImpactShake->init();
gCamFXMgr.addFX( groundImpactShake );
}
immediately after this add:
VectorF cNormal;
bool jmp = false, run = false;
findContact(&run,&jmp,&cNormal);
if((!run && !jmp) && (collision->object->getTypeMask() & TerrainObjectType))
{
if (!isGhost())
{
char normal[256];
dSprintf(normal,sizeof(normal),"%g %g %g",collision->normal.x, collision->normal.y, collision->normal.z);
Con::executef(mDataBlock,"OnSteepTerrain",scriptThis(), normal);
}
}Recompile the source.
Setup your two variables, and add your new function in player.cs
datablock PlayerData(PlayerBody)
{
...
runSurfaceAngle = 55; // change these values to suit your needs
jumpSurfaceAngle = 55;
...
}function Armor::onSteepTerrain(%this, %obj, %vec)
{
echo ("Contact with Steep Terrain");
}This should all be working ok, but I've not yet extensively tested it, so feel free to add to it if necessary.
Ian.
#2
08/17/2009 (11:02 am)
Hmm spawn a particle emitter for when the player gets to a steep part so it looks like every step he takes makes some mud go down or something
#3
08/17/2009 (11:32 am)
You don't need to call findcontact() to get the face normal,you have a collision already and just use collision->normal
#4
08/17/2009 (1:07 pm)
@Picasso: no ok I see that, but the reason i've called findcontact() is to set the bool's for run and jmp to detect the slope?
#5
08/17/2009 (3:45 pm)
OK,i misunderstood the idea. 
Minesh