Prefab, Instantiate, Transfer Speed

prefab, Instantiate, transfer speed???

How do i add transfer speed from original object to a newly created prefab???

var wreck : GameObject;// prefab -Made out of 6 parts

function Start () { yield WaitForSeconds(1); //as a test kill object in 1 sec KillSelf(); } function KillSelf () {

// creat prefab clone same position rotation var clone= Instantiate(wreck, transform.position, transform.rotation);

//set same speed to a prefab ????

Destroy(gameObject); }

function Update() {//forward Speed transform.Translate(Vector3(0,.0,1)); }

Thanks in advance

First you need to check does your instantiated object have rigidbody. And then use this code:

//...
var object_to_destroy:Transform;//=GameObject.Find(...);
var instantiated_object = Instantiate(...);
var vel = object_to_destroy.rigidbody.velocity;
var ang_vel = object_to_destroy.rigidbody.angularVelocity;
instantiated_object.rigidbody.velocity = vel;
instantiated_object.rigidbody.angularVelocity = ang_vel;
Destroy(object_to_destroy);
//...

You move your object manually in positive local z-axis (aka forward). If you want to move the new replacement object the same way, just add a similar script to it. But i think you want something like physic-controlled debris. Since you move the object with a constant speed you just have to assign that speed to the velocity of each parts rigidbody.

If it always moves forward with a constant speed just do something like:

var wreck : GameObject; // prefab -Made out of 6 parts
var Speed : float = 20.0f;
function Start (){
    yield WaitForSeconds(1); //as a test kill object in 1 sec
    KillSelf();
}

function KillSelf (){
    // creat prefab clone same position rotation
    var clone : GameObject = Instantiate(wreck,transform.position, transform.rotation);
    var allRigidbodys : Rigidbody[] = clone.GetComponentsInChildren.<Rigidbody>();
    for (var currentRB : Rigidbody in allRigidbodys){
        currentRB.velocity = transform.forward * Speed;
    }
    Destroy(gameObject);
}

function Update(){
    //forward Speed
    transform.Translate(Vector3(0,0,Speed * Time.deltaTime));
}

I tried this with a cube as my ship and this script on it. My wreck is a prefab with 2 cubes in it and every cube have a rigidbody attached. This results in: The cube moves forward for a second and then gets replaced by the prefab. Each part (in my case the two cubes) continues moving with the same speed and starts falling down due to physics gravity.

ps. If you move objects in Update() or FixedUpdate() you should use Time.deltaTime to be framerate independent.

Use Prefab in your Game Here is the tutorial for that . Unity3D Notes: Instantiate Prefab in Your Game Tutorial . Here is demo and code for Prefab instantiate so download and try to undestand i hope u will get the solution …