Hi, it’s all about my BounceBack() Function! In my Teammate Class, my Teammate ist bouncing the Ball back pefectly with a Lerp. But when i call this Function out of my Wall Class, the Ball is not bouncing back from the Wall, its kinda shaking in a weird way.
Some Informations:
The static Variables are needed, because every class is calculating with one unique Position.
ballCollision is not static, because every Class has it’s own Instance of the Variable.
The passWay Variable is calculated once when the Ball hits a Teammate or the Wall.
I don’t know what to do, i’ve tried a lot of things like writing a own Function with the same content but still the same! i Think there is a Problem with the passWay or ballPos… This ist my first game and my first Question here =)
I Hope someone can help me. Greetings from Germany
Here’s the Code with just the important Functions/Variables
public class ball : MonoBehaviour {
protected static Vector3 ballPos;
protected static Vector3 passWay;
protected bool ballCollision;
void Update () {
ballPos = transform.position;
}
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Teammate" || collision.gameObject.tag == "Wall") {
passWay = new Vector3 (player.playerPos.x, 0, player.playerPos.z + 4);
}
}
}
public class player : ball {
public static bool ballHave
public static bool passRight;
public static bool passLeft;
}
public class teammate : player {
void Update () {
BounceBack ();
}
public void BounceBack () {
if (ballCollision && !player.ballHave) {
Ball.transform.position = Vector3.Lerp (ballPos, passWay, Time.deltaTime *3);
passRight = false;
passLeft = false;
}
}
public class wall : teammate {
void Update () {
BounceBack ();
}
void OnCollisionEnter (Collision collision) {
if (collision.gameObject.tag == "Ball") {
ballCollision = true;
}
}
}