I want only 1 collision

While reading this post, you might want to check this out (a picture about my problem)

So, Im programming a Volleyball game, where the user hits the ball from below or next to the ball.

In the picture if the user’s green area and the ball collide, the ball should move to right and if the user’s red area collide with the ball, the ball jumps up (and black is mix of these).

The problem is, that as the picture shows, I’d like to have the ball jump just up, not to the right. First the ball jumps up, yes, but the player goes still up and if/when the player is high enough, the ball’s collision thinks I want the ball to go right too.

So, in short: any ideas how the collision detection in these kind of ball games is usually made? (or how the collision detection would ignore the green area if the ball is already on the red?)

edit: I figured that the program could store the “color” of the first collision to a variable and then ignore other collisions, but still the question remains, that how are those collisions usually handled?

This might help.

shmoove

I have been wondering that collision thing before and now after reading that article I know it, but it didnt help much to this current problem.

In that article (pool) the both balls will change their direction after the collision, but in my problem the player will continue its way up.

Of course I could make the player to fall down after touching the ball, but I’d like to use it only as the last resort.

May time stamp each ball-player collision on each player & disallow further collisions within a time limit.


final static long DELAY = 100; // 100ms (say)
long now = System.currentTimeMillis();
// Some code & a loop to go round all the players here
if (collision && player[i].timeLastHit + DELAY < now) {
     player[i].timeLastHit = now;
     // Process collision here
}

Alan

What I do after collisions is move the object just out of range of the collision. If you do that, you won’t have to worry about them colliding again because the volleyball will be moving faster up than the player.

[quote]What I do after collisions is move the object just out of range of the collision.
[/quote]
That sounds something I could use. Thx.

here’s another idea:


if (velocityZ < 0 && z < 1.0) //1.0 is where a collision is
   velocityZ = -velocityZ;

In this case, more than one collision does NOT get hit, because the sign of velocityZ is the first thing checked in the if statement. So if you can determine a boolean for whether or not the ball is coming TOWARD the person, you can decide whether or not it’s bouncing. If it’s coming toward and there’s a collision, bounce it. If it’s going away and there’s a collision, ignore it.