Quantcast
Channel: Questions in topic: "ignorecollision"
Viewing all articles
Browse latest Browse all 148

Trigger with object only from top side.

$
0
0
Hello. I have a little problem with detect collision (or trigger) only from top side of the object. I will try to explain what I mean using picture. ![alt text][1] When I detect collision between objects 1 and 2 they should merge. So I made child object in objects 1 and 2 with box collider (red circles). The problem is if I moved object 1 from the bottom of object 2 they collide too and merge (that shouldn't happend). I will try to show you it on second picture. ![alt text][2] So I tried to make another collider in 2nd object (under the existing one) and use Physics.IgnoreCollision when they collide, but it didn't worked. This is my code so far: void OnTriggerEnter(Collider c) { if(c.GetComponent().name == mergeWith.transform.GetChild(0).gameObject.name) { newPosition = gameObject.transform.position; newRotation = gameObject.transform.rotation; Destroy (c.gameObject.transform.parent.gameObject); Destroy (gameObject.transform.parent.gameObject); Instantiate (mergedObject, newPosition, newRotation); } } void OnTriggerStay(Collider c) { if(c.GetComponent().name == "TriggerToIgnore") { Physics.IgnoreCollision (gameObject.GetComponent(), c, true); } } void OnTriggerExit(Collider c) { if(c.GetComponent().name == "TriggerToIgnore") { Physics.IgnoreCollision (gameObject.GetComponent(), c, false); } } As I see the problem is that program is calling OnTriggerExit all the time, so IgnoreCollision is setting to false. Is there any better way to get that (detect collision only form specific side)? [1]: /storage/temp/76501-example.png [2]: /storage/temp/76502-example-2.png

Viewing all articles
Browse latest Browse all 148

Trending Articles



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