- Home /
how to give force to ball from slow to fast....?
Hey guys... I have a game in which I am giving force to the ball(sphere) by
rigidbody.AddForce (new Vector3 (0, 0, BallSpeed), ForceMode.Impulse);
in which BallSpeed is the public variable that is used to give value from the script inspector. If I keep smaller or less value of BallSpeed variable, then the ball won't reach the desired distance and stop in between the way. and if I put larger value then the ball goes speed like bullet of gun(actually not as fast as bullet, but goes very fast in just a second). So what I wanna do is that I wanna give force to the ball so that it can startup slowly and reach the desired destination with the same force. There are gameobjects in front of the ball. So i want to let them down by my ball. but want to throw my ball slowly but at the time of the collision with the gameobject, the force should remain same(Like bowling ball which thrown slowly but falls the pins very easily). So I want to do the same like bowling ball force...!
Sorry for my poor english guys.... any suggestion/solution appreciated!
Answer by KdRWaylander · Jul 24, 2015 at 11:00 AM
Hi,
If BallSpeed is your final value, you need to multiply it by a value between 0 and 1 and make this value start at 0 and gradually rise to 1.
float coeff = 0.1f;
void Update () {
if (coeff < 1){
coeff *= 1.06; //find by how much you want to rise it at each frame
// or coeff = Mathf.Sqrt(1.5f * coeff)
// ... it depends on which shape of accel you want
}
rigidbody.AddForce (new Vector3(0, 0, coeff * BallSpeed), ForceMode.Impulse);
}
by multiplying it to coeff, its stopped moving, I mean addforce not working.
Ahah my bad, that's because i put the initial value of coeff to 0, so even if i multiply it by 150, il will still be 0 ^^
change float coeff = 0;
to float coeff = 0.1f;
thanks dude, its working, not like what I expected... but I will update it. Thanks again!
when I first time add force to the sphere, it is not giving the force, but it gives 1/10th of force to sphere.. That wasn't I expected
Your answer
![](https://koobas.hobune.stream/wayback/20220611232827im_/https://answers.unity.com/themes/thub/images/avi.jpg)