• Create Account

### #ActualMilcho

Posted 28 January 2013 - 09:07 AM

Simple bounce along the y-axis is done simply by inverting your downwards y-velocity and multiplying it by a 'bounce' factor, which should be between 0 and 1, where 0 is no bounce and 1 is perfect bounce.

From your code, I'd try changing the 'else' like this:

else {
this.velocity = -this.velocity * this.bounceFactor; // where you declare this.bounceFactor to be 0 to 1 as mentioned above
this.setY(gc.getHeight() - this.length);
}

Edit: Forgot to add: in general, bounce from any 2d surface, oriented in any direction is nearly the same, only you need to take into account the surface's normal:

1) Find speed (scalar value) of the object along the surface normal (usually by doing dot product between your velocity vector and the surface normal vector)

2) Separate your velocity vector into two parts: normal velocity, which is basically surfaceNormal*speedAlongNormal, and tangential velocity which is just myVelocityVector - normalVelocityVector

3) invert the direction of the normalVeclocityVector by multiplying by -1, and then just as above multiply by some 'bounce' factor that's 0..1 so that it scales down.

### #1Milcho

Posted 28 January 2013 - 09:02 AM

Simple bounce along the y-axis is done simply by inverting your downwards y-velocity and multiplying it by a 'bounce' factor, which should be between 0 and 1, where 0 is no bounce and 1 is perfect bounce.

From your code, I'd try changing the 'else' like this:

} else {
this.velocity = -this.velocity * this.bounceFactor;  // where you declare this.bounceFactor to be 0 to 1 as mentioned above
this.setY(gc.getHeight() - this.length);
}


PARTNERS