- Home /
take object position
i instantinated an object and want to move it to another object's coordinates.but couldn't :S. help please.thx...
Answer by e-bonneville · Jul 28, 2010 at 04:02 PM
This script should do the trick:
var object : Rigidbody; var otherObject : Transform; function Update () { // Ctrl was pressed, launch a projectile if (Input.GetButtonDown("Fire1")) { // Instantiate the projectile at the position and rotation of this transform var clone : Rigidbody; clone = Instantiate(otherObject, transform.position, transform.rotation);
clone.transform.position = otherObject.transform.position;
}
}
Put it on an empty gameObject, and don't forget to assign a prefab to be instantiated.
Answer by vietnt · Sep 23, 2010 at 08:42 AM
In addition, in case you want to see visual effect, you can use iTween.
var objToBeCloned : GameObject; var spawnPosition : Vector3; var desPosition : Vector3;
var clone : GameObject; clone = Instantiate(objToBeCloned, spawnPosition, Quaternion.identity); // Move cloned object to desPosition in a second. iTween.MoveTo(clone, desPosition, 1.0f);
Your answer
Follow this Question
Related Questions
Problem with lerp positioning 1 Answer
translate 2 Answers
Mecanim walk to target position 1 Answer
Camera not moving on mobile 0 Answers
How do I make a block move to another blocks position 1 Answer