Bounce level

Hi everyone! ! I have a simple game , the ball jumps out of border , and i have to get it to the right border . I used Force to push the ball , then the bar make it bounce .

So my question is , how can i make it bounce less when it gets on the green sides , and greater when it gets on the red area ?

Thank you in advance.

If you’re using Physics Materials (will work, but will be flakey and hard to tune in)

Create 3 colliders for the ball to bounce off of, the center collider will have a physics material with a higher bounce value. The outer colliders will have physics materials with a lower bounce value.

If you’re using forces to bounce (recommended)

Add this code to your bounce block component (or whatever you call it).

void OnCollisionEnter (Collision collision)
{
  // you may want to do some filtering here to make sure that you are acting on
  // the ball, with something like:

  if (collision.collider.GetComponent<Ball> () == null)
    return;

  // this gets the collision point in the bounce block's local space
  Vector3 contactPoint = transform.InverseTransformPoint (collision.contacts[0].point);

  // assuming the bounce block is subdivided in the X axis
  // I have -0.5f and 0.5f as hard coded values here, but
  // they can be member variables of your component too.
  if ((contactPoint.x > -0.5f) && (contactPoint.x < 0.5f))
  {
    // Apply your big force bounce here!
  }
  else
  {
    // Apply your small force bounce here!
  }
}

I hope this helps!

if i had to do this i would check the contact point against the center of your paddle
u can check a vector3 or vector2, against this midpoint to see if X is greater then or less then
the middle point and set your bounce based off this. u can also use Vector3.distance
to determine a distance as a float between two positions. so on collision u could check the distance
from the center and do it that way also.

float distance = Vector3.Distance(a.position, b.position);