Question by
anil4029 · Sep 19, 2016 at 10:37 AM ·
unity 52dcollider2draycasthit2d
2D Colliders and Raycast miss collision
Hi, I am trying to destroy game objects when player slice over them like Fruit ninja or fruit slice. I tried both collider and raycast but sometime they skip collision.
I already tried these steps :
Decrease timeStep from Time manager.
using raycast 2d
using trigger collider 2d
code is below :
private void CheckForRaycastHit()
{
Vector3 touchPos= Input.mousePosition;
Vector3 scrn = mainCamera.ScreenToWorldPoint (touchPos);
RaycastHit2D hit = Physics2D.Raycast (scrn, Vector2.zero, 20, sliceableObjects);
if (hit)
{
GameObject hitObj = hit.transform.gameObject;
if (hitObj.CompareTag ("Ring"))
Destroy (hitObj.gameObject);
}
}
And for Collider :
void OnTriggerEnter2D(Collider2D col){
if (col.CompareTag("Ring")) {
Destroy(col.gameObject);
}
}
Comment