i got two rotating objects that hit each other so i want to instantiate sparks at colliding point. (oncollision) and (ontrigger)
@robertbu i got this post ..but being a newbie i am not able to understand...can some body give complete code...thanks..also how to do it with ontrigger and oncollision. https://answers.unity.com/questions/794718/how-to-get-transform-of-contactpoint-in-oncollisio.html
Answer by lgarczyn · Jan 11, 2020 at 07:46 PM
Do you want your objects to always rotate at the same speed, or do you want them to collide with each other?
Basically if you want collision events, you need rigidbodies. No more than one of the objects can be kinematic, and neither can be triggers.
If one or both objects should accurately simulate physics (bounce against each other), it's easy. One or both of the objects should be non-kinematic, both should be non-trigger, and at least one should have an OnCollisionEnter function.
In that function, instantiate a spark prefab on the collision points, which you get from the OnCollisionEnter parameter. Or you can use a single particle system and call the Emit function on all contact points. You can also use OnCollisionStay if you want sparks to keep flashing if the objects stay together.
However if both objects are kinematic, they will pass right through each other, and you won't get any collision event.
If one or both of the objects are triggers, you'll get an OnTriggerEnter event, which doesn't tell you the contact points.
i got the concept but i need the script ..i can instantiate the sparks oncollision but i need the script to instantiate sparks at the exact collision point.(point where two bodies collide)(touch each other)
Your Collision class that you receive as an argument contains a contact point list. Use .contactPoints
or GetContact/GetContacts
for performance. This lists every single place where your colliders overlapped during the last collision.
i dont understand..can you please provide a working script?
Your answer
![](https://koobas.hobune.stream/wayback/20220612221338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there any good sample code for shooting a projectile and collision detection? 0 Answers
ANIMATION TRIGGER DOESN'T PLAY 1 Answer
Problem with colliders and triggers on game board 0 Answers
How to explode an object when it touches a trigger? 1 Answer
I can't figure out why a game object isn't being destroyed. 0 Answers