- Home /
Ball's bouncing height is not same all the time.
I have a ball bounce with a particular force when hitting the ground. As the ground is made of different blocks, when the ball bounces exactly in between the two blocks it bounces little higher, but i want it to bounce at the same height all the time. Is there a way with which I can control bounce height. By setting a max bounce height?
Image below
1: normal Height. 2: height when hitting in the middle of two blocks.
My script for bouncing the ball :::::
private bool ballBounce;
public float force;
void Update()
{
if (ballBounce)
{
ballRB.AddForce(transform.up * force);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
ballBounce = true;
}
}
void OnCollisionExit(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
ballBounce = false;
}
}
problem-pic.png
(4.7 kB)
Comment
I have platforms at a different height. I want it to jump higher and come down on pressing up and down arrow at greater speed. Using clamps will I be able to do that?
Your answer