Public Group

#### Archived

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

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

## Recommended Posts

This has really been bugging the hell out of me for the last couple days. Here's my situation: I tried making a version of Slime Volleyball from http://diddly.com/slime and it's been going fine until I get to some object collision. Here's my code for detecting ball/slime collision (slimes are semicircles, the ball is a circle):

CBall::Update()
{
//Do some other collision checks

//Slime check

//If the ball's X value, fX, is less than zero, then

//it is on the left side of the net check the left slime

if(fX<0.0f)
{
//Rough check of distance between slime/ball

{
//Get the angle in radians of the collision

fAngle=atan((fY-pSlime[0]->fY)/(fX-pSlime[0]->fX));
//Get the magnitude of the ball speed

float fMag=Distance(fXVelocity/1.5f,0,fYVelocity,0);

//Determine the ball's new velocity

//X velocity is 1.5x Y velocity

fXVelocity=1.5f*fMag*cos(fAngle);

//I don't know why I have to check this, but it's the only way it works

if(fAngle<0)
{
fXVelocity*=-1;
fYVelocity=fMag*sin(-fAngle);
}
//Check when the ball is below the slime and will collide with the slime

{
//=================PROBLEM HERE================

//This is the closest I can get it to working

//=============================================

//Set Y Velocity to a certain value because I can't get it to work otherwise

fYVelocity=-0.005f;
//fYVelocity=-abs(fYVelocity);  <--- this doesn't work

}
else
//Set YVelocity

fYVelocity=fMag*sin(fAngle);
}
else
//No collision, so slow down the ball Y Velocity

//iTimeDifference is how much time elapses every frame

//0.000005f is the acceleration due to gravity

fYVelocity-=float(iTimeDifference)*0.000005f;
}
else
//Check other side


Alright, most of this works fine EXCEPT for the part where it checks if the ball is underneath the slime. I was forced to put in that forced YVelocity because I couldn't get it to work any other way. What happens if I don't do this is the ball just shoots up through the slime as if it had collided with the top part of the slime. Can anyone please help me? Here's a link in case you want to check it out: Slime Volleyball [edited by - Kaezin on March 25, 2003 5:10:10 PM]

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632932
• Total Posts
3009295
• ### Who's Online (See full list)

There are no registered users currently online

×