- Home /
Question by
Noob_Vulcan · Mar 30, 2014 at 05:00 AM ·
collision2d-physics
Collision is not detected ???
I am making a ping pong game .I'm using physics2d for collison detections. But some time when the ball hits the objects i.e player hitters it goes through them .I dont knw why this is happening. ball collides perfectly 90% of the time time but 10% of the time it goes through them.
void OnCollisionEnter2D (Collision2D collInfo)
{
if (collInfo.collider.tag == "Player") {
// float velY = rigidbody2D.velocity.y;
// velY = velY / 2 + collInfo.collider.rigidbody2D.velocity.y / 3;
// rigidbody2D.AddForce (new Vector2 (ballSpeed, 10));
// rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x, velY);
}
if (rigidbody2D.velocity.magnitude > ballSpeed * 0.31f) //if velocity more than limit the slow it down
rigidbody2D.drag = 0.2f;
else if (rigidbody2D.velocity.magnitude < ballSpeed * 0.19f) // if velocity very slow than speed it up
rigidbody2D.AddForce (new Vector2 (ballSpeed, Random.Range (10, 40)));
else
rigidbody2D.drag = 0f;
Debug.Log ("After Velc :: " + rigidbody2D.velocity.magnitude);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613141524im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Ignore Collision for 2d Collider 2 Answers
Smooth shooting in 2d orthographic camera 2 Answers
Destroy On Collision 4 Answers
Combine common surfaces 1 Answer