- Home /
Ball passing through triggered collider
Hello,
I have 2 soccer players who pass the ball to each other.
I created 2 triggered sphere colliders for each player and placed them in front of each one of them on the ground.
I am passing the ball using Rigidbody.velocity. When the ball collides with one of the sphere colliders, it should stop. Sometimes it works, but sometimes the ball just passes through the collider and continues rolling.
Here is a piece of the script attached to the ball :
//P1_Ball_Point is the sphere collider of player 1, and P2_Ball_Point is the sphere collider of player 2.
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "P1_Ball_Point") {
transform.position = P1_Ball_Point.transform.position;
}
if (other.gameObject.name == "P2_Ball_Point") {
transform.position = P2_Ball_Point.transform.position;
}
}
And in the script of the player I wrote this:
void Update () {
if (Input.GetKeyDown (KeyCode.Space) ) {
Ball.GetComponent<Rigidbody> ().velocity =
(target - Ball.transform.position) * smooth;
//I assigned 2 for smooth
}
}
So how can I let the ball reach and stop at the target without letting it pass through the triggered colliders ?
Your answer
Follow this Question
Related Questions
Ignore collision at high velocity. 1 Answer
How to measure Speed? 2 Answers
Problems with raycast accuracy 1 Answer
I am getting player tag not the other object that i want to destroy. 1 Answer
Unity 5 - Cloth falling through floor 0 Answers