Hi, im spawning some object using prefabs, like this Code (csharp): Instantiate(prefab, // transform.position, spawnPosition, Quaternion.identity); it works fine, in the prefab,cs script i try to give them each a unique travel pattern, like totally random in all direction i tried in start() to Code (csharp): rb = GetComponent<Rigidbody>(); rb.velocity = new Vector3(Random.Range(-5f, -5f), Random.Range(-5f, -5f), 0); didn't seem to work, then i moved it to update() and run it only once (using a counter and a IF) doesn't work either. at this point, im not sure in which direction i should go. Im not sure of the start() and update, are these unique for each new object spawned, or do all the object share same script, i.e. on run of update() internally updates all objects/prefabs It seems to me they are unique, but if so, i have even less clue why the code does not work any pointer would be appreciated p.s. im new to programming and game development, only done this in 3-4 days Cheers
rb.velocity=newVector3(Random.Range(-5f, 5f), Random.Range(-5f, 5f), 0); try from minimum value to maximum value -5 to 5 different gameobjects can have the same script, but they all will have their own instance (will be unique). start or update: with velocity you will change moving vector once in frame. The other forces (like gravity) will try to change this moving vector in the followed frames. If no forces act on the gameobject, then the velocity will stay the same in next frames (your start() method should be added to gameobject, which should be moved, not to spawner).
I believe vakabaka is correct, your range is between -5 and -5, so it will only output -5. Here's a shorthand for getting a random Vector2: Code (CSharp): rb.velocity = Random.insideUnitCircle * 5f;