• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# .:Collision Reaction:.

This topic is 5887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well I have the collision detecting working flawlessy, box-box method where the vehicle is inside a bounding box and the object the vehicle is colliding with is also inside a bounding box. Collision detection works great, but I'm trying to implement collision reaction in which a car collides "realistically" with a wall. For the right side or left side depending on the depth of the vehicle in comparison to the depth of the object it is colliding with, the vehicle location in relation to its local x axis is modified in relation to which side it is next to the "object". The angle is also modified so it "slides" against the wall as a car would at *certain angles*. Certain angles is my problem, the way the rotation of my vehicle is set up as a decrement of time for turning right and a increment of time for turning left in relation to accelation. So having values that are negative or positive to determine the angle is out of the question. But the method I have described above works. The problem I am having though is, if the *certain angle* is, for sakes of simplicity, "head on" the vehicle will rotate back and forth as expected. Instead I want in this case, the vehicle will "bounce" back! But how do I determine this, if I do not have any capability of referencing the angle of rotation for the vehicle itself. For clarification purposes, here's a snippet of the code I have implemented thus far:
// Separate from this function, but so you know how it works
pMesh[0].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[0].vR.x -=(*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
//where turning is done
// Collision response code below:
// Calculate the Difference in Location (X&Z) Axis Only
fXDiff = pMesh[iD2].vLoc.x - pMesh[iD].vLoc.x;
fZDiff = pMesh[iD2].vLoc.z - pMesh[iD].vLoc.z;

// Optimization of not using Sqrt Function
fLocDist = (float)fabs((fXDiff*fXDiff)+(fZDiff*fZDiff));

// Compute / Test if Location Distance is Less than Radius Distance
{
// Mesh<->Mesh Collision Detection Algorithm (Reaction)
//UpdateParticle();
// Mesh is on left side of Object it is colliding with
// Mesh is of less depth than Object
if ( (fXDiff > 0.0f) && (fZDiff > 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
}
}
// Mesh is on left side of Object it is colliding with
// Mesh is of greater depth than Object
else if ( (fXDiff > 0.0f) && (fZDiff < 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
}
}
// Mesh is on right side of Object it is colliding with
// Mesh is of less depth than Object
else if ( (fXDiff < 0.0f) && (fZDiff > 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
//pMesh[iD].fAccel -= pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x -= (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
}
// Mesh is on right side of Object it is colliding with
// Mesh is of greater depth than Object
else if ( (fXDiff < 0.0f) && (fZDiff < 0.0f) )
{
if ( pMesh[iD].fAccel > 0.0f )
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x += pMesh[iD].fAccel;
}
else
{
pMesh[iD].vR.x += (*fDelta/3.0f)+(pMesh[0].fAccel/10.0f);
pMesh[iD].vLoc.x -= pMesh[iD].fAccel;
}
}
}

If you have any suggestions or comments please let me know, I've been trying to figure out a way of doing this, just can't quite get it! =) .:Carandiru:. [edited by - Carandiru on December 6, 2002 1:41:43 AM]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634067
• Total Posts
3015323
×