I tried using a trigger to see when a ball entered an area. Everything worked as long as the ball moved at a low speed. Although when the ball was moving at a high speed the trigger would not detect the ball even though the ball had passed through the trigger. Is there any way to increase the check rate of the trigger or prevent triggers from missing objects moving through at high speeds?
I’m currently using rigidbod2D.velocity to move the ball.
I threw together a quick project to showcase the problem.
The blocks on the sides are triggers that inverse and increase the balls x velocity.
The ball script…
public class Ball : MonoBehaviour {
Rigidbody2D rb2d;
// Use this for initialization
void Start () {
rb2d = GetComponent<Rigidbody2D>();
rb2d.velocity = new Vector2(6, 0);
}
}
The block script…
public class Block : MonoBehaviour {
private void OnTriggerEnter2D(Collider2D collision)
{
GameObject obj = collision.gameObject;
if(obj.CompareTag("Ball"))
{
Rigidbody2D rb = collision.GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(-rb.velocity.x * 1.1f, rb.velocity.y);
}
}
}
How can I prevent the ball from flying threw the trigger?