Spawning objects with force so it looks like someone is randomly throwing stuff
I would like to be able to spawn objects at a random interval with some force at the start so it looks like someone who is off camera is chucking things into the view. I have no idea how to do this and I couldn't find any good tutorials. If someone could help me with this that would be great!
In case anyone was wondering, I'm making a title screen where random stuff gets randomly thrown on to the floor in front of the camera. If the player stays on the title screen for too long the room will get full of random stuff xD
It's been two weeks and still no replies...
Does anyone even browse these forums?
Answer by etopsirhc · Sep 23, 2015 at 10:51 PM
their is 2 main ways i see you could do this. 1) create a script that will apply a random force to a prefabs rigidbody as soon as it gets instantiated, then create a script to spawn them in.
2) create a script that spawns a 'dumb' (unscripted) prefab in and applies force to the object from within the spawn script.
either way you will need a prefab of the object with a rigidbody on it and a script to Instantiate the prefab at an interval.
if you use GameObject thrown = Instantiate(prefab) as GameObject; you can then pull the rigidbody up with thrown.GetComponent(); and apply a force to that in the direction you want it to be thrown. as for the timing, setting a timeSinceThrow on update to be += Time.deltaTime you can see how long it's been since you threw an object, and can throw another when it's >= the timeTillNextThrow, witch is set randomly at the end of a throw.
there's of course some more randomizing for diffrent angles and things, but once you get the base down it's not hard to see where the randomness needs to be.
Your answer
![](https://koobas.hobune.stream/wayback/20220612032839im_/https://answers.unity.com/themes/thub/images/avi.jpg)