I have a rotating block using this code attached to it:
var tr : Transform;
function Start () {
tr = transform;
}
function Update () {
tr.Rotate(0.0, 90.0*Time.deltaTime, 0.0);
}
I am firing a bullet using this code:
var speed = 500;
var bulletPrefab : Transform;
function Update () {
// Put this in your update function
if (Input.GetButtonDown("Fire1")) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Transform;
clone = Instantiate(bulletPrefab, transform.position, transform.rotation);
// Add force to the cloned object in the object's forward direction
clone.rigidbody.AddForce(clone.transform.forward * speed);
}
}
and i want to tell the bullet to stop if it hits the block and just follow the same movement the block does as if it was its child. So far i got this :
function OnTriggerEnter (hit : Collider) {
if(hit.collider.gameObject.tag == "block"){
rigidbody.isKinematic = true;
var bullet = transform;
// make it a child of the current object
bullet.parent = transform;
// place it beind the current object
bullet.localPosition = Vector3(xxx,yyy,zzz);
}
}
I dont know what to put where the xxxyyyzzz are to make it pick up the block movement and move with it 
Any help ?
thanks
If the block is just rotating you shouldn’t have to put anything.
Changing the parent adjusts the local position so that the global position stays the same.
This means that once you adjust the parent it will freeze and then begin rotation.
The thing you will have to do is remember to stop the force of the bullet.
Your OnCollision function however seems off.
You set Bullet to transform, but then set Bullet’s parent to transform, making it parent itself.
This creates an infinite loop and is going to cause large issues.
Hi again. Thanks for the answer.
Wont rigidbody.isKinematic = true; stop the force of the bullet ?
And i realize now what you mean about “making the bullet parent error” but i cant grasp the fact how to make it a child…
After the isKinematic what do i need to write to make it follow the block ? I cant understand how to do it from the documentation file.
Thanks again.
If I understand well, you are shooting bullets and want the bullets to stay at the impact point upon impact ?
yup. something like paintballing. You shoot a bullet on a movable target and if it hits it stays on it and follow the target.
I thought the easiest way of doing that is make the bullet non kinematic and then make it a child of the object it hits.
function FixedUpdate () {
if (0 < rigidbody.velocity.magnitude) {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection (rigidbody.velocity), hit, rigidbody.velocity.magnitude * Time.deltaTime)) {
transform.position = hit.point;
transform.parent = hit.transform;
rigidbody.isKinematic = true;
};
}
}
Try adding that to your bullet script.
isKinematic should work
As for getting the appropriate parenting I’d need to know which object gets the TriggerEnter
You have two objects
A Bullet
A Cube
You also have two parameters in the TriggerEnter
this
hit.gameObject
So you need:
hit.transform.parent = transform;
or
transform.parent = hit.transform;
depending on who is checking for collisions.
AkilaeTribe : That function was spawning only one bullet and it wasnt moving.
Ntero : You were right 
function OnTriggerEnter (hit : Collider) {
if(hit.collider.gameObject.tag == "block"){
rigidbody.isKinematic = true;
transform.parent = hit.transform;
}
}
Did the trick. I got this script attached to the bullet and when it hits the block i becomes its child. Exactly what i wanted 
Thanks guys!