With other method still had some problems so cooked up another method that used manual direction calculation.
My Directions
directions[0] =Vector3.up;
directions[1] =Vector3.down;
directions[2] =Vector3.Lerp(Vector3.up,Vector3.left, 0.25f);//
directions[3] =Vector3.Lerp(Vector3.up,Vector3.left, 0.5f);
directions[4] = Vector3.Lerp(Vector3.up,Vector3.left, 0.75f);
directions[5] = Vector3.Lerp(Vector3.left,Vector3.down,0.25f);
directions[6] = Vector3.Lerp(Vector3.left,Vector3.down,0.5f);
directions[7] =Vector3.Lerp(Vector3.left,Vector3.down,0.75f);
directions[8] =-Vector3.Lerp(Vector3.up,Vector3.left, 0.25f);
directions[9] =-Vector3.Lerp(Vector3.up,Vector3.left, 0.5f);
directions[10] = -Vector3.Lerp(Vector3.up,Vector3.left, 0.75f);
directions[11] = -Vector3.Lerp(Vector3.left,Vector3.down,0.25f);
directions[12] = -Vector3.Lerp(Vector3.left,Vector3.down,0.5f);
directions[13] =-Vector3.Lerp(Vector3.left,Vector3.down,0.75f);
I omitted the left and right directions b/c didn't need them in my game.
Changed
Vector3 vect = transform.position += ballVelocity * (ballSpeed + setting.GetComponent<settings>().difficulty) * Time.deltaTime ;
TO:
if(transform.gameObject.rigidbody != null)
{
transform.gameObject.rigidbody.velocity = ballVelocity * (ballSpeed + setting.GetComponent<settings>().difficulty) ;
}
uses the physics engine to do the movement like others suggested, but have to make sure to set velocity back to zero to stop the object when it doesn't need to move.
and my direction recalculating function
private Vector3 bounce(Vector3 Direction, Vector3 normal)
{
if (normal == Vector3.up)
{
if (Direction == directions[1])
{
Direction = directions[0];
}
else if (Direction == directions[8])
{
Direction = directions[13];
}
else if (Direction == directions[9])
{
Direction = directions[12];
}
else if (Direction == directions[10])
{
Direction = directions[11];
}
else if (Direction == directions[7])
{
Direction = directions[2];
}
else if (Direction == directions[6])
{
Direction = directions[3];
}
else if (Direction == directions[5])
{
Direction = directions[4];
}
}
else if (normal == Vector3.down)
{
if (Direction == directions[0])
{
Direction = directions[1];
}
else if (Direction == directions[13])
{
Direction = directions[8];
}
else if (Direction == directions[12])
{
Direction = directions[9];
}
else if (Direction == directions[11])
{
Direction = directions[10];
}
else if (Direction == directions[2])
{
Direction = directions[7];
}
else if (Direction == directions[3])
{
Direction = directions[6];
}
else if (Direction == directions[4])
{
Direction = directions[5];
}
}
else if (normal == Vector3.left)
{
if (Direction == directions[13])
{
Direction = directions[2];
}
else if (Direction == directions[12])
{
Direction = directions[3];
}
else if (Direction == directions[11])
{
Direction = directions[4];
}
else if (Direction == directions[10])
{
Direction = directions[5];
}
else if (Direction == directions[9])
{
Direction = directions[6];
}
else if (Direction == directions[8])
{
Direction = directions[7];
}
}
else if (normal == Vector3.right)
{
if (Direction == directions[2])
{
Direction = directions[13];
}
else if (Direction == directions[3])
{
Direction = directions[12];
}
else if (Direction == directions[4])
{
Direction = directions[11];
}
else if (Direction == directions[5])
{
Direction = directions[10];
}
else if (Direction == directions[6])
{
Direction = directions[9];
}
else if (Direction == directions[7])
{
Direction = directions[8];
}
}
else
{
Direction = -Direction;
error = normal;
}
return Direction;
}