It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I am using Unity3D.
avatar
kajal: I am using Unity3D.
This is not really the unity3D forum, and your question is quite vague.
You can start with this code, which can help you teleport the object in a random direction with the force you pass as a parameter, then you will need to adapt it so it moves in the direction instead of teleporting, for this you can use Lerp:
http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

static float RandFloat()
{
Random random = new Random();
double d = (random.NextDouble() * 2.0) - 1.0;
return (float)(d);
}

void Throw (float force)
{
var dir = new Vector3(RandFloat(), RandFloat(), RandFloat());
transform.Translate(dir * force);
}
Post edited September 04, 2014 by Kaeladar
high rated
avatar
kajal: how to throw object in random direction?
You take the object you want to throw in your hand. Grip it firmly. Lift it and/or pull back your hand. Move your hand as quickly as you can in the desired direction and release the object. The object should now continue to fly in the direction that your hand was moving prior to release. If that worked, congratulations, you have just thrown an object. If it didn't work keep practicing and work on your timing. It is important that you release the object while your hand is still in motion. If you release it too late, it will just fall and that is not 'throwing' but 'dropping an object'.
avatar
Lifthrasil: You take the object you want to throw in your hand. ...
The problem with your solution is that it doesn't satisfy the requirement for randomness. Humans are notoriously bad as random number (or in this case direction) generators.
avatar
Lifthrasil: You take the object you want to throw in your hand. ...
avatar
ET3D: The problem with your solution is that it doesn't satisfy the requirement for randomness. Humans are notoriously bad as random number (or in this case direction) generators.
Add a blindfold...
avatar
Lifthrasil: You take the object you want to throw in your hand. ...
avatar
ET3D: The problem with your solution is that it doesn't satisfy the requirement for randomness. Humans are notoriously bad as random number (or in this case direction) generators.
type '360' into random.org and grab a compass!
avatar
ET3D: The problem with your solution is that it doesn't satisfy the requirement for randomness. Humans are notoriously bad as random number (or in this case direction) generators.
avatar
Fever_Discordia: type '360' into random.org and grab a compass!
I think with this addition the solution should be complete! :-)