• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Sphere to Plane Collision - Getting opposite direction

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1Muzzy A  Members

Posted 23 June 2013 - 04:00 AM

// Structs
struct Sphere
{
Vector3 center;
};
struct Plane
{
Vector3 normal;
float offset;
};

// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}
// Reacting to the collision
bool SphereToPlaneReaction( Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}



Ok when i collide against a plane the direction that it moves the sphere back to is basically the reflection of what it is actually supposed to be.

if the plane is flat on the ground it works perfectly but as soon as it has rotation, the it gets put in the opposite direction that it's supposed to.

I tried reflecting the final position across the normal but that didnt work. any ideas?

EDIT: I fixed it, I was calculating the normal wrong for the plane

Edited by Muzzy A, 23 June 2013 - 04:40 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.