# Rigidbody - Applying One-Time Force? Not Constant Force

 0 Hey everybody! I'm making a game where dice are rolled. Right now what I'm working on is having the dice be randomly thrown at the Start Function. How can I do this with a rigidbody? Everything I've tried so far applies a constant force. I need to apply both a random torque and velocity. Right now what I've tried (it's constant though) is: ``````rigidbody.velocity = Vector3(Random.Range(-20.0, 20.0), 0, Random.Range(-20.0, 20.0)); rigidbody.AddTorque (Vector3.up * Random.Range(-10.0, 10.0)); `````` more ▼ asked Mar 02 '11 at 03:31 AM MythStrott 176 ● 22 ● 23 ● 31 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 more ▼ answered Mar 02 '11 at 03:42 AM digitalConundrum 156 ● 13 ● 14 ● 21 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 The way I would do it is using the rigidbody.velocity function like you did. Difference is, you probably stuck it inside your update or fixedupdate function meaning it'll happen thousands of times a second. Since you only want it executed once simply wrap it inside an if(). So on the top of your function add the variable: var shouldIThrow : boolean = true; Now inside your update or fixedupdate or whatever you use write: if(shouldIThrow) { rigidbody.velocity = stuff you had; shouldIthrow = false; } The added advantage is that now you can also set up a button or whatever you'll use to activate the dice with. If you make this button set the shouldIThrow variable to true they'll be thrown. :) more ▼ answered Mar 02 '11 at 03:53 AM Joshua 6.4k ● 19 ● 25 ● 70 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x3446
x1783
x317
x47

asked: Mar 02 '11 at 03:31 AM

Seen: 2739 times

Last Updated: Mar 02 '11 at 03:31 AM