- Home /
Instantiating at Collision Point.
First,
Here's the code.
hitParticle : GameObject;
function OnCollisionEnter(collision : Collision) { for (var contact : ContactPoint in collision.contacts) { var Hit = Instantiate (hitParticle, contact.point, contact.normal); } }
It tells me that, contact.point and contact.normal are NOT Vector3. While, if I pute .position after, it tell me that .position is not a member of Vector3... So the debug error is quite confusion... I'm missing something?
Answer by diabloroxx · Nov 30, 2010 at 12:31 AM
The correct syntax for Instantiate is : Instantiate (original : Object, position : Vector3, rotation : Quaternion) : Object You have supplied arguments like (Object,Vector3,Vector3) . It should have been Quaternion.
var hitParticle : GameObject;
function OnCollisionEnter(collision : Collision) { for (var contact : ContactPoint in collision.contacts) { var Hit = Instantiate (hitParticle, contact.point, Quaternion.identity); } }
Ah, myeah. Well it works now, I don't get the correct rotation, but I think I'll be able to handle it from there. thanks.
No problem. You can look into the Transform.Rotate to get a better idea of how the Object can be rotated.
Answer by Bunny83 · Dec 28, 2011 at 01:39 AM
I guess you want something like Quaternion.LookRotation which creates a quaternion which turns the forward axis into a given direction.
[...] Instantiate (hitParticle, contact.point, Quaternion.LookRotation(contact.normal));
Your answer
Follow this Question
Related Questions
Collision.contacts? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Question on Vector3.Reflect() 2 Answers
Get rotation from hit object 1 Answer
Safe area from enemies 1 Answer