x


Instantiate as child

I'm trying to make it so that when a collision happens, an object is instantiated at an exact point as the child of another object. How can I do this?

more ▼

asked Jan 25 '11 at 06:46 PM

Muzz 1 gravatar image

Muzz 1
548 52 59 71

Please add next time more details because your question is very abstract: when "a collision" happens; child "of another" object. And since you didn't post any code you have so far, we only can guess what language you use / want use.

Jan 25 '11 at 07:04 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I guess you use JS (because most beginners use JS ;) but i prefer C#)

One way would be something like:

var yourPrefab : Transform;
var anotherObject : Transform;

function OnCollisionEnter (collision : Collision){
   var anObject : Transform;
   anObject = Instantiate(yourPrefab, Vector3.zero, Quaternion.identity);
   anObject.parent = anotherObject;
   anObject.localRotation = Quaternion.identity; // rotates the object like the parent
   anObject.localPosition = Vector3(XX,YY,ZZ); // define here your "exact point" within the parent
}

You have to give more information whether you want a exact local or global position and if one of your "objects" is involved in the collision?

more ▼

answered Jan 25 '11 at 07:16 PM

Bunny83 gravatar image

Bunny83
45.5k 11 49 207

(comments are locked)
10|3000 characters needed characters left

You instantiate first, then you parent. You can always set position, and after the parenting, set localPosition if you want, instead.

more ▼

answered Jan 25 '11 at 07:04 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5097
x2097
x1683
x536
x414

asked: Jan 25 '11 at 06:46 PM

Seen: 2894 times

Last Updated: Jan 25 '11 at 06:46 PM