Quantcast
Channel: Questions in topic: "issue"
Viewing all articles
Browse latest Browse all 827

IsTouching() not working right after Colliders2D movement/instanciation

$
0
0
Hi I got a problem with Collider2D collisions. I'm actually working on the prodecural generation of map made of different rooms. To make sure rooms aren't colliding, I attached to each of them a Collider2D. . Problem is : Right after moving/instanciating a Collider2D and on the same method I did (=same frame), I can't use IsTouching() method with that collider. It always returns false. . I read that the colliders are not updated and I need a physical update. I tried playing with Physics.autoSyncTransforms(), Physics.SyncTransforms() and their 2D versions but it won't work. OnTriggerEnter2D and OnCollisionEnter2D won't work because all happens in a single method call (= single frame). *Note that waiting for the next FixedUpdate is not a solution because I don't want to wait 2 hours for my program to finish generating.* . Here is an example of my problem. In Start(), IsTouching() returns false. In Update(), it returns True (so colliders are working). public Collider2D c1; public Collider2D c2; void Start() { //Creating and setting up colliders2D Collider2D c1 = transform.Find("A").gameObject.AddComponent(); c1.isTrigger = true; Collider2D c2 = transform.Find("B").gameObject.AddComponent(); //Creating Rigidbody to one of them Rigidbody2D rb = transform.Find("B").gameObject.AddComponent(); rb.isKinematic = true; rb.simulated = true; Debug.LogError("test : " + c1.IsTouching(c2));//False } void Update() { Debug.LogError("test : " + c1.IsTouching(c2));//True } Please help :'(

Viewing all articles
Browse latest Browse all 827

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>