- Home /
Upon being instantiated, why is my object moving upwards ?
Everytime I instantiate a bird object, I want it to only move continuously in -Z direction. Currently it also moves upwards in Y. I don't want this upward motion to happen. Any reasons that this might be happening ? Also note that the Spawner gameobject as well as the Bird prefab have no rotation values on any axis too.
Script on GameObject that spawns the bird
public GameObject bird;
public float startFiringAfter;
public float fireEvery;
void Start () {
InvokeRepeating ("firebird", startFiringAfter, fireEvery);
}
void firebird ()
{
GameObject clone;
clone = Instantiate(bird, transform.position, transform.rotation) as GameObject;
}
Script on the Bird GameObject that is spawned
public float speed;
void Update () {
transform.Translate(new Vector3 (0, 0, -speed) * Time.deltaTime);
}
Answer by coolbird22 · Nov 05, 2014 at 04:49 PM
Using the below fixed my problem.
transform.Translate(Vector3.back * speed * Time.deltaTime);
Answer by ExtremePowers · Nov 05, 2014 at 04:31 PM
Remove the script from the bird and attach a rigidbody. Then use something like this: float speed = 1.0f;
void firebird ()
{
GameObject clone;
clone = Instantiate(bird, transform.position, transform.rotation) as GameObject;
close.AddForce(Vector3.forward * speed);
}
I don't wish to use Physics and hereby rigidbody. I want it to be a plain value increment thing in the Z axis. Sorry I didn't add this in the original message.
Your answer
Follow this Question
Related Questions
How to instantiate on custom rotation? 1 Answer
Physics related rotation problem. (a weird one) 0 Answers
Network.Instatiate Problem 0 Answers
Instantiate projectile rotation 2 Answers