Game Development Community

OnCollision and terrains?

by Mike Treanor · in Technical Issues · 02/20/2008 (11:53 pm) · 2 replies

Hello,

I am trying to implement a wall slide (like in Mega Man X). The way I was planning on doing this was to detect when the player collides with something that has a slope greater than 'some amount' and then modify the gravity to slow the player's movement to the ground as long as they are touching the surface. I already have the gravity modifying down and working well, but I am getting hung up on detecting collisions with terrain (and detecting the terrain/whatever's slope).

The way I am trying to do this is in a onCollision function:

function PlayerBody::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
//Parent::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts);
echo("Collided with: " @ %srcRef.getClassName());
if (%srcObj.getClassName() $= "TerrainObjectType")
echo("Terrain Collided with");
}

As far as I can see in player.cc, the collision mask by default includes TerrainObjectType so right away when the level loads I should be getting the message "Terrain Collided with", however I get nothing. The only things this seems to be reacting to are player types and static object types (most importantly it is not responding to interiors).

In summary, I have three main questions:
1) What and where do I need to modify to get onCollision to be called when the player collides with terrain and interiors?
2) Do I need to call Parent::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts); and if so is this the right code?
3) Is there a function or some easy-ish way to detect the slope of a point?

I've looked for some sort of resource about this and surprisingly didn't find anything... Thanks very much for your help :)

#1
02/23/2008 (9:39 am)
I think it is this

function Armor::onCollision(%this,%obj,%col,%vec,%speed)
{
//Parent::onCollision(%this,%obj,%col,%vec,%speed);
echo("Collided with: " @ %srcRef.getClassName());
if (%obj.getClassName() $= "TerrainObjectType")
echo("Terrain Collided with");
}

You need to apply it to the armor i think, Not the player object. Try it see if it works.

Mite need to be instead of %obj.getclassname(); it mite need to do it to the %col i forget what object it sends for what value.
#2
02/25/2008 (3:02 pm)
Thanks for the reply Skylar,

I am not using armor and the onCollision that I am calling on PlayerBody works well with static objects and player's...

Any other ideas?