Question by
axaytsg · Feb 07, 2016 at 12:37 AM ·
c#instantiatevelocity
Spawning objects with a fixed velocity in 3D?
I wanted to make a sort of flappy bird clone, but in 3D with objects like cube or cylinder instead of sprites.
I put in this code for the pipe object :
public class obstacle : MonoBehaviour {
public Vector2 velocity = new Vector2 (-4, 0);
void Start () {
GetComponent<Rigidbody>().velocity = velocity;
}
}
And this one for it's prefab:
public class generate : MonoBehaviour { public GameObject pipe;
void Start () {
InvokeRepeating ("CreateObstacle", 1f, 3f);
}
void CreateObstacle(){
Instantiate (pipe);
}
}
It seems to work alright in 2D with sprites, but breaks down in 3D. Object is instantiated, but does not move at all.
Any way to move them in a set direction with a fixed velocity?
Comment