- Home /
Object overlap marking
Scenario: so I have two objects. one is a needle and the other is a heart. I am trying to figure out how I can create marking to show where I stabbed the heart with the needle in the virtual reality plane. I am trying to do this by with an if case that if the colliders of the two objects were to overlap, I would create small cubes, but no luck. Help me work through this please!
So just to verify, You're looking for something that is similar or very close to: Indicate the point of impact.
Sorry didn't mean to add that as an answer.
Yes but in an augmented reality plane between two objects
You could either use raycasts in every frame and get the point
of the RaycastHit
, or the contacts
member of Collision
, that you receive from OnCollisionEnter/Stay/Exit()
functions.
Something like this (this script would go on the needle):
private void OnCollisionEnter (Collision collision) {
if (collision.collider.CompareTag("Heart)) { // or use whatever method you detect that you touched the heart
ContactPoint[] contacts = collision.contacts;
for (int i = 0; i < contacts.Length; ++i) {
Instantiate(touch$$anonymous$$arker, contacts[i].point, Quaternion.Euler(contacts[i].normal));
}
}
}
I would recommend using an object pool for the stab markers, in order to not overload the system with Instantiate
and too many markers.
Your answer
Follow this Question
Related Questions
Unity Colliders are Overlapping/Intersecting 2 Answers
(2D intersection+picture)How to show up the invisible object when intersect with another object. 1 Answer
Make mesh from overlapping colliders/triggers 0 Answers
Is there a functionality for finding how much two objects intersect each other 2 Answers
What's the best/easiest way to do something like Bounds.Intersects but accounting for rotation? 1 Answer